Sanitize query: preserve keys without values

pull/215/head
M66B 6 months ago
parent bcf8c93f01
commit 0db20e8806

@ -419,31 +419,44 @@ public class UriHelper {
path = path.toLowerCase(Locale.ROOT);
boolean first = "www.facebook.com".equals(host);
for (String key : url.getQueryParameterNames()) {
// https://en.wikipedia.org/wiki/UTM_parameters
// https://docs.oracle.com/en/cloud/saas/marketing/eloqua-user/Help/EloquaAsynchronousTrackingScripts/EloquaTrackingParameters.htm
String lkey = key.toLowerCase(Locale.ROOT);
if (PARANOID_QUERY.contains(lkey) ||
lkey.startsWith("utm_") ||
lkey.startsWith("elq") ||
((host != null && host.endsWith("facebook.com")) &&
!first &&
FACEBOOK_WHITELIST_PATH.contains(path) &&
!FACEBOOK_WHITELIST_QUERY.contains(lkey)) ||
("store.steampowered.com".equals(host) &&
"snr".equals(lkey)))
changed = true;
else if (!TextUtils.isEmpty(key))
for (String value : url.getQueryParameters(key)) {
Log.i("Query " + key + "=" + value);
Uri suri = Uri.parse(value);
String q = url.getEncodedQuery();
if (q != null) {
StringBuilder sb = new StringBuilder();
for (String kv : q.split("&")) {
int eq = kv.indexOf('=');
String key = (eq < 0 ? kv : kv.substring(0, eq));
String value = (eq < 0 ? null : kv.substring(eq + 1));
// https://en.wikipedia.org/wiki/UTM_parameters
// https://docs.oracle.com/en/cloud/saas/marketing/eloqua-user/Help/EloquaAsynchronousTrackingScripts/EloquaTrackingParameters.htm
String lkey = key.toLowerCase(Locale.ROOT);
if (PARANOID_QUERY.contains(lkey) ||
lkey.startsWith("utm_") ||
lkey.startsWith("elq") ||
((host != null && host.endsWith("facebook.com")) &&
!first &&
FACEBOOK_WHITELIST_PATH.contains(path) &&
!FACEBOOK_WHITELIST_QUERY.contains(lkey)) ||
("store.steampowered.com".equals(host) &&
"snr".equals(lkey)))
changed = true;
else if (!TextUtils.isEmpty(key)) {
Uri suri = Uri.parse(key);
if (suri != null && isHyperLink(suri)) {
Uri s = sanitize(context, suri);
return (s == null ? suri : s);
}
builder.appendQueryParameter(key, value);
if (sb.length() > 0)
sb.append('&');
sb.append(key);
if (value != null) {
sb.append('=').append(value);
}
}
first = false;
first = false;
}
if (sb.length() > 0)
builder.encodedQuery(sb.toString());
}
return (changed ? builder.build() : null);

Loading…
Cancel
Save