mirror of
https://github.com/zxing/zxing.git
synced 2025-01-27 11:01:00 -08:00
Add some necessary test changes. Some strange strings are now recognized as URL-like but it isn't a problem. Don't lowercase URI schemes.
git-svn-id: https://zxing.googlecode.com/svn/trunk@2321 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
fd38b08e1d
commit
eacb5bc3ff
|
@ -16,7 +16,6 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
|
@ -78,7 +77,7 @@ public final class URIParsedResult extends ParsedResult {
|
|||
uri = "http://" + uri;
|
||||
} else {
|
||||
// Lowercase protocol to avoid problems
|
||||
uri = uri.substring(0, protocolEnd).toLowerCase(Locale.ENGLISH) + uri.substring(protocolEnd);
|
||||
uri = uri.substring(0, protocolEnd) + uri.substring(protocolEnd);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public final class URIResultParser extends ResultParser {
|
|||
private static final String ALPHANUM_PART = "[a-zA-Z0-9\\-]";
|
||||
private static final Pattern URL_WITH_PROTOCOL_PATTERN = Pattern.compile("[a-zA-Z0-9]{2,}:");
|
||||
private static final Pattern URL_WITHOUT_PROTOCOL_PATTERN = Pattern.compile(
|
||||
"(" + ALPHANUM_PART + "+\\.)+" + ALPHANUM_PART + "{2,}" + // host name elements
|
||||
'(' + ALPHANUM_PART + "+\\.)+" + ALPHANUM_PART + "{2,}" + // host name elements
|
||||
"(:\\d{1,5})?" + // maybe port
|
||||
"(/|\\?|$)"); // query, path or nothing
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public final class ParsedReaderResultTestCase extends Assert {
|
|||
ParsedResultType.TEXT);
|
||||
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.",
|
||||
ParsedResultType.TEXT);
|
||||
ParsedResultType.URI); // Yeah, it's OK that this is thought of as maybe a URI
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -50,7 +50,7 @@ public final class ParsedReaderResultTestCase extends Assert {
|
|||
doTestResult("MEBKM:TITLE:Google;URL:google.com;;", "Google\nhttp://google.com",
|
||||
ParsedResultType.URI);
|
||||
doTestResult("MEBKM:URL:http://google.com;;", "http://google.com", ParsedResultType.URI);
|
||||
doTestResult("MEBKM:URL:HTTPS://google.com;;", "https://google.com", ParsedResultType.URI);
|
||||
doTestResult("MEBKM:URL:HTTPS://google.com;;", "HTTPS://google.com", ParsedResultType.URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -72,7 +72,8 @@ public final class ParsedReaderResultTestCase extends Assert {
|
|||
doTestResult("MATMSG:SUB:Stuff;BODY:This is some text;TO:srowen@example.org;;",
|
||||
"srowen@example.org\nStuff\nThis is some text", ParsedResultType.EMAIL_ADDRESS);
|
||||
doTestResult("TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;",
|
||||
"TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedResultType.TEXT);
|
||||
"TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedResultType.URI);
|
||||
// Yeah, it's OK that this is thought of as maybe a URI as long as it's not EMAIL_ADDRESS
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -152,7 +153,7 @@ public final class ParsedReaderResultTestCase extends Assert {
|
|||
doTestResult("http://google.com", "http://google.com", ParsedResultType.URI);
|
||||
doTestResult("google.com", "http://google.com", ParsedResultType.URI);
|
||||
doTestResult("https://google.com", "https://google.com", ParsedResultType.URI);
|
||||
doTestResult("HTTP://google.com", "http://google.com", ParsedResultType.URI);
|
||||
doTestResult("HTTP://google.com", "HTTP://google.com", ParsedResultType.URI);
|
||||
doTestResult("http://google.com/foobar", "http://google.com/foobar", ParsedResultType.URI);
|
||||
doTestResult("https://google.com:443/foobar", "https://google.com:443/foobar", ParsedResultType.URI);
|
||||
doTestResult("google.com:443", "http://google.com:443", ParsedResultType.URI);
|
||||
|
@ -222,12 +223,13 @@ public final class ParsedReaderResultTestCase extends Assert {
|
|||
doTestResult("BEGIN:VEVENT\r\nSUMMARY:foo\r\nDTSTART:20080504\r\nEND:VEVENT",
|
||||
"foo\n20080504", ParsedResultType.CALENDAR);
|
||||
doTestResult("BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT",
|
||||
"BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT", ParsedResultType.TEXT);
|
||||
"BEGIN:VEVENT\r\nDTEND:20080505T\r\nEND:VEVENT", ParsedResultType.URI);
|
||||
// Yeah, it's OK that this is thought of as maybe a URI as long as it's not CALENDAR
|
||||
// Make sure illegal entries without newlines don't crash
|
||||
doTestResult(
|
||||
"BEGIN:VEVENTSUMMARY:EventDTSTART:20081030T122030ZDTEND:20081030T132030ZEND:VEVENT",
|
||||
"BEGIN:VEVENTSUMMARY:EventDTSTART:20081030T122030ZDTEND:20081030T132030ZEND:VEVENT",
|
||||
ParsedResultType.TEXT);
|
||||
ParsedResultType.URI);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue