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:
Sean Owen 2014-03-06 07:48:04 +00:00
parent 912bee4138
commit b94a980138
2 changed files with 10 additions and 3 deletions

View file

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

View file

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