mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 04:54:04 -08:00
Issue 1295 allow broader definition of URI
git-svn-id: https://zxing.googlecode.com/svn/trunk@2318 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
4eec01a5da
commit
585318cb22
|
@ -28,23 +28,20 @@ import java.util.regex.Pattern;
|
|||
*/
|
||||
public final class URIResultParser extends ResultParser {
|
||||
|
||||
private static final String PATTERN_END =
|
||||
"(:\\d{1,5})?" + // maybe port
|
||||
"(/|\\?|$)"; // query, path or nothing
|
||||
private static final Pattern URL_WITH_PROTOCOL_PATTERN = Pattern.compile(
|
||||
"[a-zA-Z0-9]{2,}:(/)*" + // protocol
|
||||
"[a-zA-Z0-9\\-]+(\\.[a-zA-Z0-9\\-]+)*" + // host name elements
|
||||
PATTERN_END);
|
||||
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(
|
||||
"([a-zA-Z0-9\\-]+\\.)+[a-zA-Z0-9\\-]{2,}" + // host name elements
|
||||
PATTERN_END);
|
||||
"(" + ALPHANUM_PART + "+\\.)+" + ALPHANUM_PART + "{2,}" + // host name elements
|
||||
"(:\\d{1,5})?" + // maybe port
|
||||
"(/|\\?|$)"); // query, path or nothing
|
||||
|
||||
@Override
|
||||
public URIParsedResult parse(Result result) {
|
||||
String rawText = getMassagedText(result);
|
||||
// We specifically handle the odd "URL" scheme here for simplicity
|
||||
if (rawText.startsWith("URL:")) {
|
||||
rawText = rawText.substring(4);
|
||||
// We specifically handle the odd "URL" scheme here for simplicity and add "URI" for fun
|
||||
// Assume anything starting this way really means to be a URI
|
||||
if (rawText.startsWith("URL:") || rawText.startsWith("URI:")) {
|
||||
return new URIParsedResult(rawText.substring(4).trim(), null);
|
||||
}
|
||||
rawText = rawText.trim();
|
||||
return isBasicallyValidURI(rawText) ? new URIParsedResult(rawText, null) : null;
|
||||
|
|
|
@ -91,6 +91,15 @@ public final class URIParsedResultTestCase extends Assert {
|
|||
@Test
|
||||
public void testExotic() {
|
||||
doTest("bitcoin:mySD89iqpmptrK3PhHFW9fa7BXiP7ANy3Y", "bitcoin:mySD89iqpmptrK3PhHFW9fa7BXiP7ANy3Y", null);
|
||||
doTest("BTCTX:-TC4TO3$ZYZTC5NC83/SYOV+YGUGK:$BSF0P8/STNTKTKS.V84+JSA$LB+EHCG+8A725.2AZ-NAVX3VBV5K4MH7UL2.2M:" +
|
||||
"F*M9HSL*$2P7T*FX.ZT80GWDRV0QZBPQ+O37WDCNZBRM3EQ0S9SZP+3BPYZG02U/LA*89C2U.V1TS.CT1VF3DIN*HN3W-O-" +
|
||||
"0ZAKOAB32/.8:J501GJJTTWOA+5/6$MIYBERPZ41NJ6-WSG/*Z48ZH*LSAOEM*IXP81L:$F*W08Z60CR*C*P.JEEVI1F02J07L6+" +
|
||||
"W4L1G$/IC*$16GK6A+:I1-:LJ:Z-P3NW6Z6ADFB-F2AKE$2DWN23GYCYEWX9S8L+LF$VXEKH7/R48E32PU+A:9H:8O5",
|
||||
"btctx:-TC4TO3$ZYZTC5NC83/SYOV+YGUGK:$BSF0P8/STNTKTKS.V84+JSA$LB+EHCG+8A725.2AZ-NAVX3VBV5K4MH7UL2.2M:" +
|
||||
"F*M9HSL*$2P7T*FX.ZT80GWDRV0QZBPQ+O37WDCNZBRM3EQ0S9SZP+3BPYZG02U/LA*89C2U.V1TS.CT1VF3DIN*HN3W-O-" +
|
||||
"0ZAKOAB32/.8:J501GJJTTWOA+5/6$MIYBERPZ41NJ6-WSG/*Z48ZH*LSAOEM*IXP81L:$F*W08Z60CR*C*P.JEEVI1F02J07L6+" +
|
||||
"W4L1G$/IC*$16GK6A+:I1-:LJ:Z-P3NW6Z6ADFB-F2AKE$2DWN23GYCYEWX9S8L+LF$VXEKH7/R48E32PU+A:9H:8O5",
|
||||
null);
|
||||
}
|
||||
|
||||
private static void doTest(String contents, String uri, String title) {
|
||||
|
|
Loading…
Reference in a new issue