mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Issue #80 : address case where barcode text has a matching escape sequence, and better handle problematic case of URL escape sequences like %f2 matching the %f placeholder
This commit is contained in:
parent
912bee4138
commit
b94a980138
|
@ -109,7 +109,10 @@ public final class PreferencesFragment
|
|||
}
|
||||
// Before validating, remove custom placeholders, which will not
|
||||
// be considered valid parts of the URL in some locations:
|
||||
valueString = valueString.replaceAll("%[sdf]", "");
|
||||
// Blank %d and %s:
|
||||
valueString = valueString.replaceAll("%[sd]", "");
|
||||
// Blank %f but not if followed by digit or a-f as it may be a hex sequence
|
||||
valueString = valueString.replaceAll("%f(?![0-9a-f])", "");
|
||||
// Require a scheme otherwise:
|
||||
try {
|
||||
URI uri = new URI(valueString);
|
||||
|
|
|
@ -464,14 +464,18 @@ public abstract class ResultHandler {
|
|||
} catch (UnsupportedEncodingException e) {
|
||||
// can't happen; UTF-8 is always supported. Continue, I guess, without encoding
|
||||
}
|
||||
String url = customProductSearch.replace("%s", text);
|
||||
String url = text;
|
||||
if (rawResult != null) {
|
||||
url = url.replace("%f", rawResult.getBarcodeFormat().toString());
|
||||
// Replace %f but only if it doesn't seem to be a hex escape sequence. This remains
|
||||
// problematic but avoids the more surprising problem of breaking escapes
|
||||
url = url.replace("%f(?![0-9a-f])", rawResult.getBarcodeFormat().toString());
|
||||
if (url.contains("%t")) {
|
||||
ParsedResult parsedResultAgain = ResultParser.parseResult(rawResult);
|
||||
url = url.replace("%t", parsedResultAgain.getType().toString());
|
||||
}
|
||||
}
|
||||
// Replace %s last as it might contain itself %f or %t
|
||||
url = customProductSearch.replace("%s", url);
|
||||
return url;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue