@@ -590,25 +590,25 @@ public boolean isAllowed(int c) {
590
590
AUTHORITY {
591
591
@ Override
592
592
public boolean isAllowed (int c ) {
593
- return isUnreserved ( c ) || isSubDelimiter (c ) || ':' == c || '@' == c ;
593
+ return ( isUnreservedOrSubDelimiter (c ) || ':' == c || '@' == c ) ;
594
594
}
595
595
},
596
596
USER_INFO {
597
597
@ Override
598
598
public boolean isAllowed (int c ) {
599
- return isUnreserved ( c ) || isSubDelimiter (c ) || ':' == c ;
599
+ return ( isUnreservedOrSubDelimiter (c ) || ':' == c ) ;
600
600
}
601
601
},
602
602
HOST_IPV4 {
603
603
@ Override
604
604
public boolean isAllowed (int c ) {
605
- return isUnreserved ( c ) || isSubDelimiter (c );
605
+ return isUnreservedOrSubDelimiter (c );
606
606
}
607
607
},
608
608
HOST_IPV6 {
609
609
@ Override
610
610
public boolean isAllowed (int c ) {
611
- return isUnreserved ( c ) || isSubDelimiter (c ) || '[' == c || ']' == c || ':' == c ;
611
+ return ( isUnreservedOrSubDelimiter (c ) || '[' == c || ']' == c || ':' == c ) ;
612
612
}
613
613
},
614
614
PORT {
@@ -620,7 +620,7 @@ public boolean isAllowed(int c) {
620
620
PATH {
621
621
@ Override
622
622
public boolean isAllowed (int c ) {
623
- return isPchar (c ) || '/' == c ;
623
+ return ( isPchar (c ) || '/' == c ) ;
624
624
}
625
625
},
626
626
PATH_SEGMENT {
@@ -632,7 +632,7 @@ public boolean isAllowed(int c) {
632
632
QUERY {
633
633
@ Override
634
634
public boolean isAllowed (int c ) {
635
- return isPchar (c ) || '/' == c || '?' == c ;
635
+ return ( isPchar (c ) || '/' == c || '?' == c ) ;
636
636
}
637
637
},
638
638
QUERY_PARAM {
@@ -642,14 +642,14 @@ public boolean isAllowed(int c) {
642
642
return false ;
643
643
}
644
644
else {
645
- return isPchar (c ) || '/' == c || '?' == c ;
645
+ return ( isPchar (c ) || '/' == c || '?' == c ) ;
646
646
}
647
647
}
648
648
},
649
649
FRAGMENT {
650
650
@ Override
651
651
public boolean isAllowed (int c ) {
652
- return isPchar (c ) || '/' == c || '?' == c ;
652
+ return ( isPchar (c ) || '/' == c || '?' == c ) ;
653
653
}
654
654
},
655
655
URI {
@@ -659,6 +659,15 @@ public boolean isAllowed(int c) {
659
659
}
660
660
};
661
661
662
+ private static final boolean [] unreservedOrSubDelimiterArray = new boolean [128 ];
663
+
664
+ static {
665
+ for (int i = 0 ; i < 128 ; i ++) {
666
+ char c = (char ) i ;
667
+ unreservedOrSubDelimiterArray [i ] = (URI .isUnreserved (c ) || URI .isSubDelimiter (c ));
668
+ }
669
+ }
670
+
662
671
/**
663
672
* Indicates whether the given character is allowed in this URI component.
664
673
* @return {@code true} if the character is allowed; {@code false} otherwise
@@ -694,8 +703,8 @@ protected boolean isGenericDelimiter(int c) {
694
703
* @see <a href="https://www.ietf.org/rfc/rfc3986.txt">RFC 3986, appendix A</a>
695
704
*/
696
705
protected boolean isSubDelimiter (int c ) {
697
- return ('!' == c || '$' == c || '&' == c || '\'' == c || '(' == c || ')' == c || '*' == c || '+' == c ||
698
- ',' == c || ';' == c || '=' == c );
706
+ return ('!' == c || '$' == c || '&' == c || '\'' == c ||
707
+ '(' == c || ')' == c || '*' == c || '+' == c || ' ,' == c || ';' == c || '=' == c );
699
708
}
700
709
701
710
/**
@@ -719,8 +728,16 @@ protected boolean isUnreserved(int c) {
719
728
* @see <a href="https://www.ietf.org/rfc/rfc3986.txt">RFC 3986, appendix A</a>
720
729
*/
721
730
protected boolean isPchar (int c ) {
722
- return (isUnreserved ( c ) || isSubDelimiter (c ) || ':' == c || '@' == c );
731
+ return (isUnreservedOrSubDelimiter (c ) || ':' == c || '@' == c );
723
732
}
733
+
734
+ /**
735
+ * Combined check whether a character is unreserved or a sub-delimiter.
736
+ */
737
+ protected boolean isUnreservedOrSubDelimiter (int c ) {
738
+ return (c < unreservedOrSubDelimiterArray .length && c >= 0 && unreservedOrSubDelimiterArray [c ]);
739
+ }
740
+
724
741
}
725
742
726
743
0 commit comments