File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
main/java/org/scribe/utils
test/java/org/scribe/utils Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 1212public class Preconditions
1313{
1414 private static final String DEFAULT_MESSAGE = "Received an invalid parameter" ;
15- private static final Pattern URL_PATTERN = Pattern .compile ("[a-zA-Z_-]+://\\ S+" );
15+
16+ // scheme = alpha *( alpha | digit | "+" | "-" | "." )
17+ private static final Pattern URL_PATTERN = Pattern .compile ("^[a-zA-Z][a-zA-Z0-9+.-]*://\\ S+" );
1618
1719 /**
1820 * Checks that an object is not null.
Original file line number Diff line number Diff line change @@ -43,16 +43,25 @@ public void shouldThrowExceptionForNullUrls()
4343 Preconditions .checkValidUrl (null , ERROR_MSG );
4444 }
4545
46+ @ Test
4647 public void shouldAllowValidUrls ()
4748 {
4849 Preconditions .checkValidUrl ("http://www.example.com" , ERROR_MSG );
4950 }
5051
52+ @ Test
5153 public void shouldAllowSSLUrls ()
5254 {
5355 Preconditions .checkValidUrl ("https://www.example.com" , ERROR_MSG );
5456 }
57+
58+ @ Test
59+ public void shouldAllowSpecialCharsInScheme ()
60+ {
61+ Preconditions .checkValidUrl ("custom+9.3-1://www.example.com" , ERROR_MSG );
62+ }
5563
64+ @ Test
5665 public void shouldAllowNonStandarProtocolsForAndroid ()
5766 {
5867 Preconditions .checkValidUrl ("x-url-custom://www.example.com" , ERROR_MSG );
@@ -64,6 +73,13 @@ public void shouldNotAllowStrangeProtocolNames()
6473 Preconditions .checkValidUrl ("$weird*://www.example.com" , ERROR_MSG );
6574 }
6675
76+ @ Test (expected = IllegalArgumentException .class )
77+ public void shouldNotAllowUnderscoreInScheme ()
78+ {
79+ Preconditions .checkValidUrl ("http_custom://www.example.com" , ERROR_MSG );
80+ }
81+
82+ @ Test
6783 public void shouldAllowOutOfBandAsValidCallbackValue ()
6884 {
6985 Preconditions .checkValidOAuthCallback ("oob" , ERROR_MSG );
You can’t perform that action at this time.
0 commit comments