mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Make sure strings with a space aren't considered a URI
git-svn-id: https://zxing.googlecode.com/svn/trunk@2586 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
e5d060bfe7
commit
cd8985336d
|
@ -47,7 +47,11 @@ public final class URIResultParser extends ResultParser {
|
||||||
return isBasicallyValidURI(rawText) ? new URIParsedResult(rawText, null) : null;
|
return isBasicallyValidURI(rawText) ? new URIParsedResult(rawText, null) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isBasicallyValidURI(CharSequence uri) {
|
static boolean isBasicallyValidURI(String uri) {
|
||||||
|
if (uri.contains(" ")) {
|
||||||
|
// Quick hack check for a common case
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Matcher m = URL_WITH_PROTOCOL_PATTERN.matcher(uri);
|
Matcher m = URL_WITH_PROTOCOL_PATTERN.matcher(uri);
|
||||||
if (m.find() && m.start() == 0) { // match at start only
|
if (m.find() && m.start() == 0) { // match at start only
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -49,7 +49,7 @@ public final class ParsedReaderResultTestCase extends Assert {
|
||||||
ParsedResultType.TEXT);
|
ParsedResultType.TEXT);
|
||||||
doTestResult("This: a test with lots of @ nearly-random punctuation! No? OK then.",
|
doTestResult("This: a test with lots of @ nearly-random punctuation! No? OK then.",
|
||||||
"This: a test with lots of @ nearly-random punctuation! No? OK then.",
|
"This: a test with lots of @ nearly-random punctuation! No? OK then.",
|
||||||
ParsedResultType.URI); // Yeah, it's OK that this is thought of as maybe a URI
|
ParsedResultType.TEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -82,8 +82,7 @@ public final class ParsedReaderResultTestCase extends Assert {
|
||||||
doTestResult("MATMSG:SUB:Stuff;BODY:This is some text;TO:srowen@example.org;;",
|
doTestResult("MATMSG:SUB:Stuff;BODY:This is some text;TO:srowen@example.org;;",
|
||||||
"srowen@example.org\nStuff\nThis is some text", ParsedResultType.EMAIL_ADDRESS);
|
"srowen@example.org\nStuff\nThis is some text", ParsedResultType.EMAIL_ADDRESS);
|
||||||
doTestResult("TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;",
|
doTestResult("TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;",
|
||||||
"TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedResultType.URI);
|
"TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedResultType.TEXT);
|
||||||
// Yeah, it's OK that this is thought of as maybe a URI as long as it's not EMAIL_ADDRESS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -57,6 +57,7 @@ public final class URIParsedResultTestCase extends Assert {
|
||||||
doTestNotUri(".com");
|
doTestNotUri(".com");
|
||||||
doTestNotUri(":80/");
|
doTestNotUri(":80/");
|
||||||
doTestNotUri("ABC,20.3,AB,AD");
|
doTestNotUri("ABC,20.3,AB,AD");
|
||||||
|
doTestNotUri("http://google.com?q=foo bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue