Allow digits in URL schemes per RFC
This commit is contained in:
1 parent
89ddd131e4
commit
d39f7ab3fc
2 files changed
+19
-1
No files matched your search
@@ -12,7 +12,9 @@ import org.scribe.model.OAuthConstants;
|
||||
public class Preconditions
|
||||
{
|
||||
private static final String DEFAULT_MESSAGE = "Received an invalid parameter";
|
||||
private static final Pattern URL_PATTERN = Pattern.compile("[a-zA-Z_-]+://\\S+");
|
||||
|
||||
// scheme = alpha *( alpha | digit | "+" | "-" | "." )
|
||||
private static final Pattern URL_PATTERN = Pattern.compile("^[a-zA-Z][a-zA-Z0-9+.-]*://\\S+");
|
||||
|
||||
/**
|
||||
* Checks that an object is not null.
|
||||
|
||||
@@ -43,16 +43,25 @@ public class PreconditionsTest
|
||||
Preconditions.checkValidUrl(null, ERROR_MSG);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAllowValidUrls()
|
||||
{
|
||||
Preconditions.checkValidUrl("http://www.example.com", ERROR_MSG);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAllowSSLUrls()
|
||||
{
|
||||
Preconditions.checkValidUrl("https://www.example.com", ERROR_MSG);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAllowSpecialCharsInScheme()
|
||||
{
|
||||
Preconditions.checkValidUrl("custom+9.3-1://www.example.com", ERROR_MSG);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAllowNonStandarProtocolsForAndroid()
|
||||
{
|
||||
Preconditions.checkValidUrl("x-url-custom://www.example.com", ERROR_MSG);
|
||||
@@ -64,6 +73,13 @@ public class PreconditionsTest
|
||||
Preconditions.checkValidUrl("$weird*://www.example.com", ERROR_MSG);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldNotAllowUnderscoreInScheme()
|
||||
{
|
||||
Preconditions.checkValidUrl("http_custom://www.example.com", ERROR_MSG);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAllowOutOfBandAsValidCallbackValue()
|
||||
{
|
||||
Preconditions.checkValidOAuthCallback("oob", ERROR_MSG);
|
||||
|
||||
Reference in new issue
Block a user