57
57
* @author Arjen Poutsma
58
58
* @since 6.2
59
59
*/
60
+ @ SuppressWarnings ({"SameParameterValue" , "BooleanMethodIsAlwaysInverted" })
60
61
final class WhatWgUrlParser {
61
62
62
63
public static final UrlRecord EMPTY_RECORD = new UrlRecord ();
@@ -140,7 +141,7 @@ public static UrlRecord parse(String input, @Nullable UrlRecord base,
140
141
/**
141
142
* The basic URL parser takes a scalar value string input, with an optional
142
143
* null or base URL base (default null), an optional encoding (default UTF-8),
143
- * an optional UrlRecord, and an optional state override .
144
+ * and optionally, a UrlRecord and/or State overrides to start from .
144
145
*/
145
146
private UrlRecord basicUrlParser (@ Nullable UrlRecord url , @ Nullable State stateOverride ) {
146
147
// If url is not given:
@@ -471,6 +472,7 @@ private static boolean isNonCharacter(int ch) {
471
472
ch == 0xEFFFE || ch == 0xEFFFF || ch == 0xFFFFE || ch == 0xFFFFF || ch == 0x10FFFE || ch == 0x10FFFF );
472
473
}
473
474
475
+ @ SuppressWarnings ("BooleanMethodIsAlwaysInverted" )
474
476
private static boolean isUrlCodePoint (int ch ) {
475
477
return (isAsciiAlphaNumeric (ch ) ||
476
478
ch == '!' || ch == '$' || ch == '&' || ch == '\'' || ch == '(' || ch == ')' ||
@@ -490,10 +492,8 @@ private static int defaultPort(@Nullable String scheme) {
490
492
if (scheme != null ) {
491
493
return switch (scheme ) {
492
494
case "ftp" -> 21 ;
493
- case "http" -> 80 ;
494
- case "https" -> 443 ;
495
- case "ws" -> 80 ;
496
- case "wss" -> 443 ;
495
+ case "http" , "ws" -> 80 ;
496
+ case "https" , "wss" -> 443 ;
497
497
default -> -1 ;
498
498
};
499
499
}
@@ -686,10 +686,9 @@ private static boolean isDoubleDotPathSegment(StringBuilder b) {
686
686
687
687
/**
688
688
* A Windows drive letter is two code points, of which the first is an ASCII alpha
689
- * and the second is either U+003A (:) or U+007C (|).
690
- *
689
+ * and the second is either U+003A {@code (:)} or U+007C {@code (|)}.
691
690
* A normalized Windows drive letter is a Windows drive letter of which
692
- * the second code point is U+003A (:).
691
+ * the second code point is U+003A {@code (:)} .
693
692
*/
694
693
private static boolean isWindowsDriveLetter (CharSequence input , boolean normalized ) {
695
694
if (input .length () != 2 ) {
@@ -699,8 +698,7 @@ private static boolean isWindowsDriveLetter(CharSequence input, boolean normaliz
699
698
}
700
699
701
700
/**
702
- * A string starts with a Windows drive letter if all of the following are true:
703
- *
701
+ * A string starts with a Windows drive letter if all the following are true:
704
702
* its length is greater than or equal to 2
705
703
* its first two code points are a Windows drive letter
706
704
* its length is 2 or its third code point is U+002F (/), U+005C (\), U+003F (?), or U+0023 (#).
@@ -1204,7 +1202,6 @@ else if (p.stateOverride != null && p.buffer.isEmpty() &&
1204
1202
// If state override is given, then return.
1205
1203
if (p .stateOverride != null ) {
1206
1204
p .stopMainLoop = true ;
1207
- return ;
1208
1205
}
1209
1206
}
1210
1207
// Otherwise:
@@ -1656,7 +1653,7 @@ public void handle(int c, UrlRecord url, WhatWgUrlParser p) {
1656
1653
}
1657
1654
}
1658
1655
// Otherwise, if c is not the EOF code point:
1659
- else if ( c != EOF ) {
1656
+ else {
1660
1657
if (p .validate ()) {
1661
1658
// If c is not a URL code point and not U+0025 (%), invalid-URL-unit validation error.
1662
1659
if (!isUrlCodePoint (c ) && c != '%' ) {
@@ -1769,39 +1766,6 @@ public boolean hasOpaquePath() {
1769
1766
}
1770
1767
1771
1768
1772
- /**
1773
- * The serialization of an origin is the string obtained by applying
1774
- * the following algorithm to the given origin:
1775
- * <ol>
1776
- * <li>If origin is an opaque origin, then return "null".
1777
- * <li>Otherwise, let result be origin's scheme.
1778
- * <li>Append "://" to result.
1779
- * Append origin's host, serialized, to result.
1780
- * <li>If origin's port is non-null, append a U+003A COLON character (:),
1781
- * and origin's port, serialized, to result.
1782
- * <li>Return result.
1783
- * </ol>
1784
- */
1785
- public String origin () {
1786
- String scheme = scheme ();
1787
- if (scheme .equals ("ftp" ) ||
1788
- scheme .equals ("http" ) || scheme .equals ("https" ) ||
1789
- scheme .equals ("ws" ) || scheme .equals ("wss" )) {
1790
- StringBuilder builder = new StringBuilder (scheme );
1791
- builder .append ("://" );
1792
- builder .append (host ());
1793
- Port port = port ();
1794
- if (port != null ) {
1795
- builder .append (':' );
1796
- builder .append (port );
1797
- }
1798
- return builder .toString ();
1799
- }
1800
- else {
1801
- return "null" ;
1802
- }
1803
- }
1804
-
1805
1769
/**
1806
1770
* A URL’s scheme is an ASCII string that identifies the type of URL and
1807
1771
* can be used to dispatch a URL for further processing after parsing.
@@ -1814,6 +1778,7 @@ public String scheme() {
1814
1778
/**
1815
1779
* The protocol getter steps are to return this’s URL’s scheme, followed by U+003A (:).
1816
1780
*/
1781
+ @ SuppressWarnings ("unused" )
1817
1782
public String protocol () {
1818
1783
return scheme () + ":" ;
1819
1784
}
@@ -1899,6 +1864,7 @@ public Host host() {
1899
1864
* <li>Return url’s host, serialized, followed by U+003A (:) and url’s port, serialized.
1900
1865
* </ol>
1901
1866
*/
1867
+ @ SuppressWarnings ("unused" )
1902
1868
public String hostString () {
1903
1869
if (host () == null ) {
1904
1870
return "" ;
@@ -2001,6 +1967,7 @@ public String fragment() {
2001
1967
* <li>Return U+0023 (#), followed by this’s URL’s fragment.
2002
1968
* </ol>
2003
1969
*/
1970
+ @ SuppressWarnings ("unused" )
2004
1971
public String hash () {
2005
1972
String fragment = fragment ();
2006
1973
return (fragment != null && !fragment .isEmpty () ? "#" + fragment : "" );
@@ -2248,6 +2215,7 @@ static final class IpAddressHost implements Host {
2248
2215
}
2249
2216
}
2250
2217
2218
+ @ SuppressWarnings ("unused" )
2251
2219
public IpAddress address () {
2252
2220
return this .address ;
2253
2221
}
@@ -2776,7 +2744,7 @@ else if (c != EOF) {
2776
2744
}
2777
2745
// Otherwise, if compress is null and pieceIndex is not 8,
2778
2746
// IPv6-too-few-pieces validation error, return failure.
2779
- else if (compress == null && pieceIndex != 8 ) {
2747
+ else if (pieceIndex != 8 ) {
2780
2748
throw new InvalidUrlException ("An uncompressed IPv6 address contains fewer than 8 pieces." );
2781
2749
}
2782
2750
// Return address.
@@ -3019,6 +2987,7 @@ public boolean isOpaque() {
3019
2987
return true ;
3020
2988
}
3021
2989
2990
+ @ SuppressWarnings ("MethodDoesntCallSuperMethod" )
3022
2991
@ Override
3023
2992
public Path clone () {
3024
2993
return new PathSegment (segment ());
@@ -3103,6 +3072,7 @@ public boolean isOpaque() {
3103
3072
return false ;
3104
3073
}
3105
3074
3075
+ @ SuppressWarnings ("MethodDoesntCallSuperMethod" )
3106
3076
@ Override
3107
3077
public Path clone () {
3108
3078
return new PathSegments (this .segments );
0 commit comments