3ffa63f52acecc2b6c0f01c203571ebc45c73523de4d2f0359ea8ff5d701c679fe9ccffbf6df0a0ff4fe0655b84274d2993d2071f6ad28b7727186eade8a6c-exec 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. const RFC3986 = require('./rfc3986');
  3. const internals = {
  4. Uri: {
  5. createUriRegex: function (optionalScheme, allowRelative, relativeOnly, allowQuerySquareBrackets) {
  6. let scheme = RFC3986.scheme;
  7. let prefix;
  8. if (relativeOnly) {
  9. prefix = '(?:' + RFC3986.relativeRef + ')';
  10. }
  11. else {
  12. // If we were passed a scheme, use it instead of the generic one
  13. if (optionalScheme) {
  14. // Have to put this in a non-capturing group to handle the OR statements
  15. scheme = '(?:' + optionalScheme + ')';
  16. }
  17. const withScheme = '(?:' + scheme + ':' + RFC3986.hierPart + ')';
  18. prefix = allowRelative ? '(?:' + withScheme + '|' + RFC3986.relativeRef + ')' : withScheme;
  19. }
  20. /**
  21. * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
  22. *
  23. * OR
  24. *
  25. * relative-ref = relative-part [ "?" query ] [ "#" fragment ]
  26. */
  27. return new RegExp('^' + prefix + '(?:\\?' + (allowQuerySquareBrackets ? RFC3986.queryWithSquareBrackets : RFC3986.query) + ')?' + '(?:#' + RFC3986.fragment + ')?$');
  28. }
  29. }
  30. };
  31. module.exports = internals.Uri;