From 1a499bbee5b82dc217794702ba51b786f2757904 Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Mon, 15 Jun 2015 15:55:02 +0300 Subject: [PATCH] Bug 1093611 - Stage 2 - Make hash getters not do percent decoding if dom.url.getters_decode_hash is false r=smaug --- dom/base/Link.cpp | 2 +- dom/base/URL.cpp | 2 +- dom/base/nsContentUtils.cpp | 4 ++++ dom/base/nsContentUtils.h | 9 +++++++++ dom/base/nsLocation.cpp | 2 +- dom/workers/WorkerPrivate.cpp | 2 +- modules/libpref/init/all.js | 2 ++ 7 files changed, 19 insertions(+), 4 deletions(-) diff --git a/dom/base/Link.cpp b/dom/base/Link.cpp index d9881aec2f0..856f3e32965 100644 --- a/dom/base/Link.cpp +++ b/dom/base/Link.cpp @@ -444,7 +444,7 @@ Link::GetHash(nsAString &_hash, ErrorResult& aError) nsresult rv = uri->GetRef(ref); if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) { _hash.Assign(char16_t('#')); - if (nsContentUtils::EncodeDecodeURLHash()) { + if (nsContentUtils::GettersDecodeURLHash()) { NS_UnescapeURL(ref); // XXX may result in random non-ASCII bytes! } AppendUTF8toUTF16(ref, _hash); diff --git a/dom/base/URL.cpp b/dom/base/URL.cpp index 5ab46d5fd99..438c3ddfd22 100644 --- a/dom/base/URL.cpp +++ b/dom/base/URL.cpp @@ -525,7 +525,7 @@ URL::GetHash(nsAString& aHash, ErrorResult& aRv) const nsresult rv = mURI->GetRef(ref); if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) { aHash.Assign(char16_t('#')); - if (nsContentUtils::EncodeDecodeURLHash()) { + if (nsContentUtils::GettersDecodeURLHash()) { NS_UnescapeURL(ref); // XXX may result in random non-ASCII bytes! } AppendUTF8toUTF16(ref, aHash); diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index c7991278c59..23abc0a5343 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -256,6 +256,7 @@ bool nsContentUtils::sIsResourceTimingEnabled = false; bool nsContentUtils::sIsUserTimingLoggingEnabled = false; bool nsContentUtils::sIsExperimentalAutocompleteEnabled = false; bool nsContentUtils::sEncodeDecodeURLHash = false; +bool nsContentUtils::sGettersDecodeURLHash = false; bool nsContentUtils::sPrivacyResistFingerprinting = false; uint32_t nsContentUtils::sHandlingInputTimeout = 1000; @@ -538,6 +539,9 @@ nsContentUtils::Init() Preferences::AddBoolVarCache(&sEncodeDecodeURLHash, "dom.url.encode_decode_hash", false); + Preferences::AddBoolVarCache(&sGettersDecodeURLHash, + "dom.url.getters_decode_hash", false); + Preferences::AddBoolVarCache(&sPrivacyResistFingerprinting, "privacy.resistFingerprinting", false); diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index fc6eb677053..e2e676e9ed3 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -1948,6 +1948,14 @@ public: return sEncodeDecodeURLHash; } + /* + * Returns true if URL getters should percent decode the value of the segment + */ + static bool GettersDecodeURLHash() + { + return sGettersDecodeURLHash && sEncodeDecodeURLHash; + } + /* * Returns true if the browser should attempt to prevent content scripts * from collecting distinctive information about the browser that could @@ -2499,6 +2507,7 @@ private: static bool sIsUserTimingLoggingEnabled; static bool sIsExperimentalAutocompleteEnabled; static bool sEncodeDecodeURLHash; + static bool sGettersDecodeURLHash; static bool sPrivacyResistFingerprinting; static nsHtml5StringParser* sHTMLFragmentParser; diff --git a/dom/base/nsLocation.cpp b/dom/base/nsLocation.cpp index f578deaafff..6e2cc280b2b 100644 --- a/dom/base/nsLocation.cpp +++ b/dom/base/nsLocation.cpp @@ -299,7 +299,7 @@ nsLocation::GetHash(nsAString& aHash) rv = uri->GetRef(ref); - if (nsContentUtils::EncodeDecodeURLHash()) { + if (nsContentUtils::GettersDecodeURLHash()) { if (NS_SUCCEEDED(rv)) { nsCOMPtr textToSubURI( do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv)); diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index a917d6eccc5..787b0584aef 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -4095,7 +4095,7 @@ WorkerPrivateParent::SetBaseURI(nsIURI* aBaseURI) if (NS_SUCCEEDED(aBaseURI->GetRef(temp)) && !temp.IsEmpty()) { nsCOMPtr converter = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID); - if (converter && nsContentUtils::EncodeDecodeURLHash()) { + if (converter && nsContentUtils::GettersDecodeURLHash()) { nsCString charset; nsAutoString unicodeRef; if (NS_SUCCEEDED(aBaseURI->GetOriginCharset(charset)) && diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 96df9392ef6..c4cd87c1ce0 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -169,6 +169,8 @@ pref("dom.undo_manager.enabled", false); // Whether URL,nsLocation,Link::GetHash should be percent encoded // in setter and percent decoded in getter (old behaviour = true) pref("dom.url.encode_decode_hash", true); +// Whether ::GetHash should do percent decoding (old behaviour = true) +pref("dom.url.getters_decode_hash", false); // Whether to run add-on code in different compartments from browser code. This // causes a separate compartment for each (addon, global) combination, which may