Skip to content

Commit d39f7ab

Browse files
author
Seth Hitchings
committed
Allow digits in URL schemes per RFC
1 parent 89ddd13 commit d39f7ab

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/main/java/org/scribe/utils/Preconditions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
public 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.

src/test/java/org/scribe/utils/PreconditionsTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)