6cd01611457868fafb36bdbe1ea282c709c8814be83f4fe5340f13502f37110d0e13748610c76684eaba1f353ff14aea1e5853afc1e83882d03105aa99c095-exec 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. 'use strict';
  2. const internals = {
  3. rfc3986: {}
  4. };
  5. internals.generate = function () {
  6. /**
  7. * elements separated by forward slash ("/") are alternatives.
  8. */
  9. const or = '|';
  10. /**
  11. * Rule to support zero-padded addresses.
  12. */
  13. const zeroPad = '0?';
  14. /**
  15. * DIGIT = %x30-39 ; 0-9
  16. */
  17. const digit = '0-9';
  18. const digitOnly = '[' + digit + ']';
  19. /**
  20. * ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
  21. */
  22. const alpha = 'a-zA-Z';
  23. const alphaOnly = '[' + alpha + ']';
  24. /**
  25. * IPv4
  26. * cidr = DIGIT ; 0-9
  27. * / %x31-32 DIGIT ; 10-29
  28. * / "3" %x30-32 ; 30-32
  29. */
  30. internals.rfc3986.ipv4Cidr = digitOnly + or + '[1-2]' + digitOnly + or + '3' + '[0-2]';
  31. /**
  32. * IPv6
  33. * cidr = DIGIT ; 0-9
  34. * / %x31-39 DIGIT ; 10-99
  35. * / "1" %x0-1 DIGIT ; 100-119
  36. * / "12" %x0-8 ; 120-128
  37. */
  38. internals.rfc3986.ipv6Cidr = '(?:' + zeroPad + zeroPad + digitOnly + or + zeroPad + '[1-9]' + digitOnly + or + '1' + '[01]' + digitOnly + or + '12[0-8])';
  39. /**
  40. * HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
  41. */
  42. const hexDigit = digit + 'A-Fa-f';
  43. const hexDigitOnly = '[' + hexDigit + ']';
  44. /**
  45. * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
  46. */
  47. const unreserved = alpha + digit + '-\\._~';
  48. /**
  49. * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
  50. */
  51. const subDelims = '!\\$&\'\\(\\)\\*\\+,;=';
  52. /**
  53. * pct-encoded = "%" HEXDIG HEXDIG
  54. */
  55. const pctEncoded = '%' + hexDigit;
  56. /**
  57. * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
  58. */
  59. const pchar = unreserved + pctEncoded + subDelims + ':@';
  60. const pcharOnly = '[' + pchar + ']';
  61. /**
  62. * squareBrackets example: []
  63. */
  64. const squareBrackets = '\\[\\]';
  65. /**
  66. * dec-octet = DIGIT ; 0-9
  67. * / %x31-39 DIGIT ; 10-99
  68. * / "1" 2DIGIT ; 100-199
  69. * / "2" %x30-34 DIGIT ; 200-249
  70. * / "25" %x30-35 ; 250-255
  71. */
  72. const decOctect = '(?:' + zeroPad + zeroPad + digitOnly + or + zeroPad + '[1-9]' + digitOnly + or + '1' + digitOnly + digitOnly + or + '2' + '[0-4]' + digitOnly + or + '25' + '[0-5])';
  73. /**
  74. * IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
  75. */
  76. internals.rfc3986.IPv4address = '(?:' + decOctect + '\\.){3}' + decOctect;
  77. /**
  78. * h16 = 1*4HEXDIG ; 16 bits of address represented in hexadecimal
  79. * ls32 = ( h16 ":" h16 ) / IPv4address ; least-significant 32 bits of address
  80. * IPv6address = 6( h16 ":" ) ls32
  81. * / "::" 5( h16 ":" ) ls32
  82. * / [ h16 ] "::" 4( h16 ":" ) ls32
  83. * / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
  84. * / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
  85. * / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
  86. * / [ *4( h16 ":" ) h16 ] "::" ls32
  87. * / [ *5( h16 ":" ) h16 ] "::" h16
  88. * / [ *6( h16 ":" ) h16 ] "::"
  89. */
  90. const h16 = hexDigitOnly + '{1,4}';
  91. const ls32 = '(?:' + h16 + ':' + h16 + '|' + internals.rfc3986.IPv4address + ')';
  92. const IPv6SixHex = '(?:' + h16 + ':){6}' + ls32;
  93. const IPv6FiveHex = '::(?:' + h16 + ':){5}' + ls32;
  94. const IPv6FourHex = '(?:' + h16 + ')?::(?:' + h16 + ':){4}' + ls32;
  95. const IPv6ThreeHex = '(?:(?:' + h16 + ':){0,1}' + h16 + ')?::(?:' + h16 + ':){3}' + ls32;
  96. const IPv6TwoHex = '(?:(?:' + h16 + ':){0,2}' + h16 + ')?::(?:' + h16 + ':){2}' + ls32;
  97. const IPv6OneHex = '(?:(?:' + h16 + ':){0,3}' + h16 + ')?::' + h16 + ':' + ls32;
  98. const IPv6NoneHex = '(?:(?:' + h16 + ':){0,4}' + h16 + ')?::' + ls32;
  99. const IPv6NoneHex2 = '(?:(?:' + h16 + ':){0,5}' + h16 + ')?::' + h16;
  100. const IPv6NoneHex3 = '(?:(?:' + h16 + ':){0,6}' + h16 + ')?::';
  101. internals.rfc3986.IPv6address = '(?:' + IPv6SixHex + or + IPv6FiveHex + or + IPv6FourHex + or + IPv6ThreeHex + or + IPv6TwoHex + or + IPv6OneHex + or + IPv6NoneHex + or + IPv6NoneHex2 + or + IPv6NoneHex3 + ')';
  102. /**
  103. * IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
  104. */
  105. internals.rfc3986.IPvFuture = 'v' + hexDigitOnly + '+\\.[' + unreserved + subDelims + ':]+';
  106. /**
  107. * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  108. */
  109. internals.rfc3986.scheme = alphaOnly + '[' + alpha + digit + '+-\\.]*';
  110. /**
  111. * userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
  112. */
  113. const userinfo = '[' + unreserved + pctEncoded + subDelims + ':]*';
  114. /**
  115. * IP-literal = "[" ( IPv6address / IPvFuture ) "]"
  116. */
  117. const IPLiteral = '\\[(?:' + internals.rfc3986.IPv6address + or + internals.rfc3986.IPvFuture + ')\\]';
  118. /**
  119. * reg-name = *( unreserved / pct-encoded / sub-delims )
  120. */
  121. const regName = '[' + unreserved + pctEncoded + subDelims + ']{0,255}';
  122. /**
  123. * host = IP-literal / IPv4address / reg-name
  124. */
  125. const host = '(?:' + IPLiteral + or + internals.rfc3986.IPv4address + or + regName + ')';
  126. /**
  127. * port = *DIGIT
  128. */
  129. const port = digitOnly + '*';
  130. /**
  131. * authority = [ userinfo "@" ] host [ ":" port ]
  132. */
  133. const authority = '(?:' + userinfo + '@)?' + host + '(?::' + port + ')?';
  134. /**
  135. * segment = *pchar
  136. * segment-nz = 1*pchar
  137. * path = path-abempty ; begins with "/" or is empty
  138. * / path-absolute ; begins with "/" but not "//"
  139. * / path-noscheme ; begins with a non-colon segment
  140. * / path-rootless ; begins with a segment
  141. * / path-empty ; zero characters
  142. * path-abempty = *( "/" segment )
  143. * path-absolute = "/" [ segment-nz *( "/" segment ) ]
  144. * path-rootless = segment-nz *( "/" segment )
  145. */
  146. const segment = pcharOnly + '*';
  147. const segmentNz = pcharOnly + '+';
  148. const segmentNzNc = '[' + unreserved + pctEncoded + subDelims + '@' + ']+';
  149. const pathEmpty = '';
  150. const pathAbEmpty = '(?:\\/' + segment + ')*';
  151. const pathAbsolute = '\\/(?:' + segmentNz + pathAbEmpty + ')?';
  152. const pathRootless = segmentNz + pathAbEmpty;
  153. const pathNoScheme = segmentNzNc + pathAbEmpty;
  154. /**
  155. * hier-part = "//" authority path
  156. */
  157. internals.rfc3986.hierPart = '(?:' + '(?:\\/\\/' + authority + pathAbEmpty + ')' + or + pathAbsolute + or + pathRootless + ')';
  158. /**
  159. * relative-part = "//" authority path-abempty
  160. * / path-absolute
  161. * / path-noscheme
  162. * / path-empty
  163. */
  164. internals.rfc3986.relativeRef = '(?:' + '(?:\\/\\/' + authority + pathAbEmpty + ')' + or + pathAbsolute + or + pathNoScheme + or + pathEmpty + ')';
  165. /**
  166. * query = *( pchar / "/" / "?" )
  167. */
  168. internals.rfc3986.query = '[' + pchar + '\\/\\?]*(?=#|$)'; //Finish matching either at the fragment part or end of the line.
  169. /**
  170. * query = *( pchar / "[" / "]" / "/" / "?" )
  171. */
  172. internals.rfc3986.queryWithSquareBrackets = '[' + pchar + squareBrackets + '\\/\\?]*(?=#|$)'; //Finish matching either at the fragment part or end of the line.
  173. /**
  174. * fragment = *( pchar / "/" / "?" )
  175. */
  176. internals.rfc3986.fragment = '[' + pchar + '\\/\\?]*';
  177. };
  178. internals.generate();
  179. module.exports = internals.rfc3986;