5656 * @author Arjen Poutsma
5757 * @since 6.2
5858 */
59- final class UrlParser {
59+ final class WhatWgUrlParser {
6060
61- private static final Log logger = LogFactory .getLog (UrlParser .class );
61+ private static final Log logger = LogFactory .getLog (WhatWgUrlParser .class );
6262
6363 private static final int EOF = -1 ;
6464
@@ -98,7 +98,7 @@ final class UrlParser {
9898 private boolean stopMainLoop = false ;
9999
100100
101- private UrlParser (
101+ private WhatWgUrlParser (
102102 String input , @ Nullable UrlRecord base , @ Nullable Charset encoding ,
103103 @ Nullable Consumer <String > validationErrorHandler ) {
104104
@@ -131,7 +131,7 @@ public static UrlRecord parse(String input, @Nullable UrlRecord base,
131131
132132 Assert .notNull (input , "Input must not be null" );
133133
134- UrlParser parser = new UrlParser (input , base , encoding , validationErrorHandler );
134+ WhatWgUrlParser parser = new WhatWgUrlParser (input , base , encoding , validationErrorHandler );
135135 return parser .basicUrlParser (null , null );
136136 }
137137
@@ -743,7 +743,7 @@ private enum State {
743743
744744 SCHEME_START {
745745 @ Override
746- public void handle (int c , UrlRecord url , UrlParser p ) {
746+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
747747 // If c is an ASCII alpha, append c, lowercased, to buffer, and set state to scheme state.
748748 if (isAsciiAlpha (c )) {
749749 p .append (Character .toLowerCase ((char ) c ));
@@ -770,7 +770,7 @@ else if (p.stateOverride == null) {
770770 },
771771 SCHEME {
772772 @ Override
773- public void handle (int c , UrlRecord url , UrlParser p ) {
773+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
774774 // If c is an ASCII alphanumeric, U+002B (+), U+002D (-), or U+002E (.), append c, lowercased, to buffer.
775775 if (isAsciiAlphaNumeric (c ) || (c == '+' || c == '-' || c == '.' )) {
776776 p .append (Character .toLowerCase ((char ) c ));
@@ -868,7 +868,7 @@ else if (p.stateOverride == null) {
868868 },
869869 NO_SCHEME {
870870 @ Override
871- public void handle (int c , UrlRecord url , UrlParser p ) {
871+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
872872 // If base is null, or base has an opaque path and c is not U+0023 (#),
873873 // missing-scheme-non-relative-URL validation error, return failure.
874874 if (p .base == null || p .base .path ().isOpaque () && c != '#' ) {
@@ -901,7 +901,7 @@ else if (!"file".equals(p.base.scheme())) {
901901 },
902902 SPECIAL_RELATIVE_OR_AUTHORITY {
903903 @ Override
904- public void handle (int c , UrlRecord url , UrlParser p ) {
904+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
905905 // If c is U+002F (/) and remaining starts with U+002F (/),
906906 // then set state to special authority ignore slashes state and
907907 // increase pointer by 1.
@@ -922,7 +922,7 @@ public void handle(int c, UrlRecord url, UrlParser p) {
922922 },
923923 PATH_OR_AUTHORITY {
924924 @ Override
925- public void handle (int c , UrlRecord url , UrlParser p ) {
925+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
926926 // If c is U+002F (/), then set state to authority state.
927927 if (c == '/' ) {
928928 p .setState (AUTHORITY );
@@ -936,7 +936,7 @@ public void handle(int c, UrlRecord url, UrlParser p) {
936936 },
937937 RELATIVE {
938938 @ Override
939- public void handle (int c , UrlRecord url , UrlParser p ) {
939+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
940940 // Assert: base’s scheme is not "file".
941941 Assert .state (p .base != null && !"file" .equals (p .base .scheme ()),
942942 "Base scheme not provided or supported" );
@@ -994,7 +994,7 @@ else if (c != EOF) {
994994 },
995995 RELATIVE_SLASH {
996996 @ Override
997- public void handle (int c , UrlRecord url , UrlParser p ) {
997+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
998998 // If url is special and c is U+002F (/) or U+005C (\), then:
999999 if (url .isSpecial () && (c == '/' || c == '\\' )) {
10001000 // If c is U+005C (\), invalid-reverse-solidus validation error.
@@ -1027,7 +1027,7 @@ else if (c == '/') {
10271027 },
10281028 SPECIAL_AUTHORITY_SLASHES {
10291029 @ Override
1030- public void handle (int c , UrlRecord url , UrlParser p ) {
1030+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
10311031 // If c is U+002F (/) and remaining starts with U+002F (/),
10321032 // then set state to special authority ignore slashes state and
10331033 // increase pointer by 1.
@@ -1048,7 +1048,7 @@ public void handle(int c, UrlRecord url, UrlParser p) {
10481048 },
10491049 SPECIAL_AUTHORITY_IGNORE_SLASHES {
10501050 @ Override
1051- public void handle (int c , UrlRecord url , UrlParser p ) {
1051+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
10521052 // If c is neither U+002F (/) nor U+005C (\),
10531053 // then set state to authority state and decrease pointer by 1.
10541054 if (c != '/' && c != '\\' ) {
@@ -1065,7 +1065,7 @@ public void handle(int c, UrlRecord url, UrlParser p) {
10651065 },
10661066 AUTHORITY {
10671067 @ Override
1068- public void handle (int c , UrlRecord url , UrlParser p ) {
1068+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
10691069 // If c is U+0040 (@), then:
10701070 if (c == '@' ) {
10711071 // Invalid-credentials validation error.
@@ -1091,7 +1091,7 @@ public void handle(int c, UrlRecord url, UrlParser p) {
10911091 }
10921092 // Let encodedCodePoints be the result of running UTF-8 percent-encode codePoint
10931093 // using the userinfo percent-encode set.
1094- String encodedCodePoints = p .percentEncode (codePoint , UrlParser ::userinfoPercentEncodeSet );
1094+ String encodedCodePoints = p .percentEncode (codePoint , WhatWgUrlParser ::userinfoPercentEncodeSet );
10951095 // If passwordTokenSeen is true, then append encodedCodePoints to url’s password.
10961096 if (p .passwordTokenSeen ) {
10971097 if (encodedCodePoints != null ) {
@@ -1137,7 +1137,7 @@ else if ((c == EOF || c == '/' || c == '?' || c == '#') || (url.isSpecial() && c
11371137 },
11381138 HOST {
11391139 @ Override
1140- public void handle (int c , UrlRecord url , UrlParser p ) {
1140+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
11411141 // If state override is given and url’s scheme is "file",
11421142 // then decrease pointer by 1 and set state to file host state.
11431143 if (p .stateOverride != null && "file" .equals (url .scheme ())) {
@@ -1214,7 +1214,7 @@ else if (c == ']') {
12141214 },
12151215 PORT {
12161216 @ Override
1217- public void handle (int c , UrlRecord url , UrlParser p ) {
1217+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
12181218 // If c is an ASCII digit, append c to buffer.
12191219 if (isAsciiDigit (c )) {
12201220 p .append (c );
@@ -1281,7 +1281,7 @@ else if (c == EOF || c == '/' || c == '?' || c == '#' ||
12811281 },
12821282 FILE {
12831283 @ Override
1284- public void handle (int c , UrlRecord url , UrlParser p ) {
1284+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
12851285 // Set url’s scheme to "file".
12861286 url .scheme = "file" ;
12871287 // Set url’s host to the empty string.
@@ -1347,7 +1347,7 @@ else if (c != EOF) {
13471347 },
13481348 FILE_SLASH {
13491349 @ Override
1350- public void handle (int c , UrlRecord url , UrlParser p ) {
1350+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
13511351 // If c is U+002F (/) or U+005C (\), then:
13521352 if (c == '/' || c == '\\' ) {
13531353 // If c is U+005C (\), invalid-reverse-solidus validation error.
@@ -1382,7 +1382,7 @@ public void handle(int c, UrlRecord url, UrlParser p) {
13821382 },
13831383 FILE_HOST {
13841384 @ Override
1385- public void handle (int c , UrlRecord url , UrlParser p ) {
1385+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
13861386 // If c is the EOF code point, U+002F (/), U+005C (\), U+003F (?), or U+0023 (#),
13871387 // then decrease pointer by 1 and then:
13881388 if (c == EOF || c == '/' || c == '\\' || c == '?' || c == '#' ) {
@@ -1433,7 +1433,7 @@ else if (p.buffer.isEmpty()) {
14331433 },
14341434 PATH_START {
14351435 @ Override
1436- public void handle (int c , UrlRecord url , UrlParser p ) {
1436+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
14371437 // If url is special, then:
14381438 if (url .isSpecial ()) {
14391439 // If c is U+005C (\), invalid-reverse-solidus validation error.
@@ -1484,7 +1484,7 @@ else if (p.stateOverride != null && url.host() == null) {
14841484 },
14851485 PATH {
14861486 @ Override
1487- public void handle (int c , UrlRecord url , UrlParser p ) {
1487+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
14881488 // If one of the following is true:
14891489 // - c is the EOF code point or U+002F (/)
14901490 // - url is special and c is U+005C (\)
@@ -1563,7 +1563,7 @@ else if (c == '%' &&
15631563 }
15641564 }
15651565 // UTF-8 percent-encode c using the path percent-encode set and append the result to buffer.
1566- String encoded = p .percentEncode (c , UrlParser ::pathPercentEncodeSet );
1566+ String encoded = p .percentEncode (c , WhatWgUrlParser ::pathPercentEncodeSet );
15671567 if (encoded != null ) {
15681568 p .append (encoded );
15691569 }
@@ -1575,7 +1575,7 @@ else if (c == '%' &&
15751575 },
15761576 OPAQUE_PATH {
15771577 @ Override
1578- public void handle (int c , UrlRecord url , UrlParser p ) {
1578+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
15791579 // EXTRA: if previous state is URL Template and the buffer is empty,
15801580 // append buffer to url's path and empty the buffer
15811581 if (p .previousState == URL_TEMPLATE && !p .buffer .isEmpty ()) {
@@ -1618,7 +1618,7 @@ else if (c == '%' &&
16181618 // If c is not the EOF code point, UTF-8 percent-encode c using
16191619 // the C0 control percent-encode set and append the result to url’s path.
16201620 if (c != EOF ) {
1621- String encoded = p .percentEncode (c , UrlParser ::c0ControlPercentEncodeSet );
1621+ String encoded = p .percentEncode (c , WhatWgUrlParser ::c0ControlPercentEncodeSet );
16221622 if (encoded != null ) {
16231623 url .path .append (encoded );
16241624 }
@@ -1631,7 +1631,7 @@ else if (c == '%' &&
16311631 },
16321632 QUERY {
16331633 @ Override
1634- public void handle (int c , UrlRecord url , UrlParser p ) {
1634+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
16351635 // If encoding is not UTF-8 and one of the following is true:
16361636 // - url is not special
16371637 // - url’s scheme is "ws" or "wss"
@@ -1648,7 +1648,7 @@ public void handle(int c, UrlRecord url, UrlParser p) {
16481648 // Let queryPercentEncodeSet be the special-query percent-encode set if url is special;
16491649 // otherwise the query percent-encode set.
16501650 IntPredicate queryPercentEncodeSet = (url .isSpecial () ?
1651- UrlParser ::specialQueryPercentEncodeSet : UrlParser ::queryPercentEncodeSet );
1651+ WhatWgUrlParser ::specialQueryPercentEncodeSet : WhatWgUrlParser ::queryPercentEncodeSet );
16521652 // Percent-encode after encoding, with encoding, buffer, and queryPercentEncodeSet,
16531653 // and append the result to url’s query.
16541654 String encoded = p .percentEncode (p .buffer .toString (), queryPercentEncodeSet );
@@ -1690,7 +1690,7 @@ else if (c == '%' &&
16901690 },
16911691 FRAGMENT {
16921692 @ Override
1693- public void handle (int c , UrlRecord url , UrlParser p ) {
1693+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
16941694 // If c is not the EOF code point, then:
16951695 if (c != EOF ) {
16961696 if (p .validate ()) {
@@ -1709,7 +1709,7 @@ else if (c == '%' &&
17091709 }
17101710 // UTF-8 percent-encode c using the fragment percent-encode set and
17111711 // append the result to url’s fragment.
1712- String encoded = p .percentEncode (c , UrlParser ::fragmentPercentEncodeSet );
1712+ String encoded = p .percentEncode (c , WhatWgUrlParser ::fragmentPercentEncodeSet );
17131713 Assert .state (url .fragment != null , "Url's fragment should not be null" );
17141714 if (encoded != null ) {
17151715 url .fragment .append (encoded );
@@ -1722,7 +1722,7 @@ else if (c == '%' &&
17221722 },
17231723 URL_TEMPLATE {
17241724 @ Override
1725- public void handle (int c , UrlRecord url , UrlParser p ) {
1725+ public void handle (int c , UrlRecord url , WhatWgUrlParser p ) {
17261726 Assert .state (p .previousState != null , "No previous state set" );
17271727 if (c == '}' ) {
17281728 p .append (c );
@@ -1739,7 +1739,7 @@ else if (c == EOF) {
17391739 }
17401740 };
17411741
1742- public abstract void handle (int c , UrlRecord url , UrlParser p );
1742+ public abstract void handle (int c , UrlRecord url , WhatWgUrlParser p );
17431743
17441744 }
17451745
@@ -2133,7 +2133,7 @@ sealed interface Host permits Domain, EmptyHost, IpAddressHost, OpaqueHost {
21332133 * boolean isOpaque (default false), and then runs these steps.
21342134 * They return failure or a host.
21352135 */
2136- static Host parse (String input , boolean isOpaque , UrlParser p ) {
2136+ static Host parse (String input , boolean isOpaque , WhatWgUrlParser p ) {
21372137 // If input starts with U+005B ([), then:
21382138 if (!input .isEmpty () && input .codePointAt (0 ) == '[' ) {
21392139 int last = input .length () - 1 ;
@@ -2303,7 +2303,7 @@ private OpaqueHost(String host) {
23032303 * The opaque-host parser takes a scalar value string input,
23042304 * and then runs these steps. They return failure or an opaque host.
23052305 */
2306- public static OpaqueHost parse (String input , UrlParser p ) {
2306+ public static OpaqueHost parse (String input , WhatWgUrlParser p ) {
23072307 for (int i = 0 ; i < input .length (); i ++) {
23082308 int ch = input .codePointAt (i );
23092309 // If input contains a forbidden host code point, h
@@ -2326,7 +2326,7 @@ public static OpaqueHost parse(String input, UrlParser p) {
23262326 }
23272327 // Return the result of running UTF-8 percent-encode on input
23282328 // using the C0 control percent-encode set.
2329- String encoded = p .percentEncode (input , UrlParser ::c0ControlPercentEncodeSet );
2329+ String encoded = p .percentEncode (input , WhatWgUrlParser ::c0ControlPercentEncodeSet );
23302330 return new OpaqueHost (encoded );
23312331 }
23322332
@@ -2420,7 +2420,7 @@ private static String serialize(int address) {
24202420 return output .toString ();
24212421 }
24222422
2423- public static Ipv4Address parse (String input , UrlParser p ) {
2423+ public static Ipv4Address parse (String input , WhatWgUrlParser p ) {
24242424 // Let parts be the result of strictly splitting input on U+002E (.).
24252425 List <String > parts = strictSplit (input , '.' );
24262426 int partsSize = parts .size ();
0 commit comments