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:
srowen@gmail.com 2013-03-05 18:11:09 +00:00
parent e5d060bfe7
commit cd8985336d
3 changed files with 8 additions and 4 deletions

View file

@ -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;

View file

@ -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

View file

@ -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