Bug 1342438 - Remove url .hash encoding/decoding prefs r=bagder

These prefs have been added close to two years ago:
dom.url.encode_decode_hash and dom.url.getters_decode_hash
The main reason for their existence was in case we encounter any web-compat issues. At this point the extra code is mostly useless, and flipping the pref may lead to crashes.

MozReview-Commit-ID: LhAHkYmv0TR

--HG--
extra : rebase_source : 8f2d50d5633496cf165b3925d952bb6475bce3e0
This commit is contained in:
Valentin Gosu 2017-03-08 22:19:34 +01:00
parent 5847af980b
commit 1c5fbd8c6e
10 changed files with 13 additions and 217 deletions

View File

@ -546,9 +546,6 @@ Link::GetHash(nsAString &_hash)
nsresult rv = uri->GetRef(ref);
if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) {
_hash.Assign(char16_t('#'));
if (nsContentUtils::GettersDecodeURLHash()) {
NS_UnescapeURL(ref); // XXX may result in random non-ASCII bytes!
}
AppendUTF8toUTF16(ref, _hash);
}
}

View File

@ -308,35 +308,9 @@ Location::GetHash(nsAString& aHash)
rv = uri->GetRef(ref);
if (nsContentUtils::GettersDecodeURLHash()) {
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsITextToSubURI> textToSubURI(
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv)) {
nsAutoCString charset;
uri->GetOriginCharset(charset);
rv = textToSubURI->UnEscapeURIForUI(charset, ref, unicodeRef);
}
if (NS_FAILED(rv)) {
// Oh, well. No intl here!
NS_UnescapeURL(ref);
CopyASCIItoUTF16(ref, unicodeRef);
rv = NS_OK;
}
}
if (NS_SUCCEEDED(rv) && !unicodeRef.IsEmpty()) {
aHash.Assign(char16_t('#'));
aHash.Append(unicodeRef);
}
} else { // URL Hash should simply return the value of the Ref segment
if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) {
aHash.Assign(char16_t('#'));
AppendUTF8toUTF16(ref, aHash);
}
if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) {
aHash.Assign(char16_t('#'));
AppendUTF8toUTF16(ref, aHash);
}
if (aHash == mCachedHash) {

View File

@ -286,8 +286,6 @@ bool nsContentUtils::sIsResourceTimingEnabled = false;
bool nsContentUtils::sIsUserTimingLoggingEnabled = false;
bool nsContentUtils::sIsExperimentalAutocompleteEnabled = false;
bool nsContentUtils::sIsWebComponentsEnabled = false;
bool nsContentUtils::sEncodeDecodeURLHash = false;
bool nsContentUtils::sGettersDecodeURLHash = false;
bool nsContentUtils::sPrivacyResistFingerprinting = false;
bool nsContentUtils::sSendPerformanceTimingNotifications = false;
bool nsContentUtils::sUseActivityCursor = false;
@ -587,12 +585,6 @@ nsContentUtils::Init()
Preferences::AddBoolVarCache(&sIsWebComponentsEnabled,
"dom.webcomponents.enabled", false);
Preferences::AddBoolVarCache(&sEncodeDecodeURLHash,
"dom.url.encode_decode_hash", false);
Preferences::AddBoolVarCache(&sGettersDecodeURLHash,
"dom.url.getters_decode_hash", false);
Preferences::AddBoolVarCache(&sPrivacyResistFingerprinting,
"privacy.resistFingerprinting", false);

View File

@ -2108,23 +2108,6 @@ public:
*/
static bool IsFrameTimingEnabled();
/*
* Returns true if URL setters should percent encode the Hash/Ref segment
* and getters should return the percent decoded value of the segment
*/
static bool EncodeDecodeURLHash()
{
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 the given caller type
* from collecting distinctive information about the browser that could
@ -2916,8 +2899,6 @@ private:
static bool sIsFrameTimingPrefEnabled;
static bool sIsExperimentalAutocompleteEnabled;
static bool sIsWebComponentsEnabled;
static bool sEncodeDecodeURLHash;
static bool sGettersDecodeURLHash;
static bool sPrivacyResistFingerprinting;
static bool sSendPerformanceTimingNotifications;
static bool sUseActivityCursor;

View File

@ -583,7 +583,6 @@ support-files = file_cookiemanager.js
[test_bug871161.html]
support-files = file_bug871161-1.html file_bug871161-2.html
[test_bug1013316.html]
[test_hash_encoded.html]
[test_bug1081037.html]
[test_window_open_close.html]
tags = openwindow

View File

@ -1,118 +0,0 @@
<!doctype html>
<html>
<head>
<title>Test link.hash attribute</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<pre id="test">
<script>
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [['dom.url.encode_decode_hash', false]]}, runTest);
function runTest() {
setupTest();
doTestEncoded();
SimpleTest.finish();
}
function setupTest() {
var target1 = document.createElement("a");
target1.id = "target1";
target1.href = "http://www.example.com/#q=♥â¥#hello";
document.body.appendChild(target1);
var target2 = document.createElement("a");
target2.id = "target2";
target2.href = "http://www.example.com/#q=%E2%99%A5%C3%A2%C2%A5";
document.body.appendChild(target2);
var target3 = document.createElement("a");
target3.id = "target3";
target3.href = "http://www.example.com/#/search/%23important";
document.body.appendChild(target3);
var target4 = document.createElement("a");
target4.id = "target4";
target4.href = 'http://www.example.com/#{"a":[13, 42], "b":{"key":"value"}}';
document.body.appendChild(target4);
}
function doTestEncoded() {
// Tests Link::GetHash
// Check that characters aren't being encoded
var target = document.getElementById("target1");
is(target.hash, '#q=♥â¥#hello', 'Unexpected link hash');
// Check that encoded characters aren't being decoded
target = document.getElementById("target2");
is(target.hash, '#q=%E2%99%A5%C3%A2%C2%A5', 'Unexpected link hash');
// A more regular use case
target = document.getElementById("target3");
is(target.hash, '#/search/%23important', 'Unexpected link hash');
// Some JSON
target = document.getElementById("target4");
is(target.hash, '#{"a":[13, 42], "b":{"key":"value"}}', 'Unexpected link hash');
// Tests URL::GetHash
var url = new URL("http://www.example.com/#q=♥â¥#hello")
is(url.hash, '#q=♥â¥#hello', 'Unexpected url hash');
url = new URL("http://www.example.com/#q=%E2%99%A5%C3%A2%C2%A5")
is(url.hash, '#q=%E2%99%A5%C3%A2%C2%A5', 'Unexpected url hash');
url = new URL("http://www.example.com/#/search/%23important")
is(url.hash, '#/search/%23important', 'Unexpected url hash');
// Test getters and setters
url = new URL("http://www.example.com/");
url.hash = "#q=♥â¥#hello%E2%99%A5%C3%A2%C2%A5#/search/%23important"
is(url.hash, '#q=♥â¥#hello%E2%99%A5%C3%A2%C2%A5#/search/%23important', 'Unexpected url hash');
// codepath in nsStandardUrl::SetRef is different if the path is non-empty
url = new URL("http://www.example.com/test/");
url.hash = "#q=♥â¥#hello%E2%99%A5%C3%A2%C2%A5#/search/%23important"
is(url.hash, '#q=♥â¥#hello%E2%99%A5%C3%A2%C2%A5#/search/%23important', 'Unexpected url hash');
url = new URL("http://www.example.com/");
url.hash = '#{"a":[13, 42], "b":{"key":"value"}}';
is(target.hash, '#{"a":[13, 42], "b":{"key":"value"}}', 'Unexpected url hash');
var parsed = JSON.parse(target.hash.substring(1));
is(parsed.b.key, 'value', 'JSON not parsed correctly');
url = new URL("http://www.example.com/test/");
url.hash = '#{"a":[13, 42], "b":{"key":"value"}}';
is(target.hash, '#{"a":[13, 42], "b":{"key":"value"}}', 'Unexpected url hash');
parsed = JSON.parse(target.hash.substring(1));
is(parsed.b.key, 'value', 'JSON not parsed correctly');
// Tests Location::GetHash
window.history.pushState(1, document.title, '#q=♥â¥#hello');
is(location.hash,'#q=♥â¥#hello', 'Unexpected location hash');
window.history.pushState(1, document.title, '#q=%E2%99%A5%C3%A2%C2%A5');
is(location.hash,'#q=%E2%99%A5%C3%A2%C2%A5', 'Unexpected location hash');
window.history.pushState(1, document.title, '#/search/%23important');
is(location.hash,'#/search/%23important', 'Unexpected location hash');
window.history.pushState(1, document.title, '#{"a":[13, 42], "b":{"key":"value"}}');
is(location.hash,'#{"a":[13, 42], "b":{"key":"value"}}', 'Unexpected location hash');
}
</script>
</pre>
</body>
</html>

View File

@ -561,9 +561,6 @@ URLMainThread::GetHash(nsAString& aHash, ErrorResult& aRv) const
nsresult rv = mURI->GetRef(ref);
if (NS_SUCCEEDED(rv) && !ref.IsEmpty()) {
aHash.Assign(char16_t('#'));
if (nsContentUtils::GettersDecodeURLHash()) {
NS_UnescapeURL(ref); // XXX may result in random non-ASCII bytes!
}
AppendUTF8toUTF16(ref, aHash);
}
}

View File

@ -3875,19 +3875,6 @@ WorkerPrivateParent<Derived>::SetBaseURI(nsIURI* aBaseURI)
}
if (NS_SUCCEEDED(aBaseURI->GetRef(temp)) && !temp.IsEmpty()) {
nsCOMPtr<nsITextToSubURI> converter =
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID);
if (converter && nsContentUtils::GettersDecodeURLHash()) {
nsCString charset;
nsAutoString unicodeRef;
if (NS_SUCCEEDED(aBaseURI->GetOriginCharset(charset)) &&
NS_SUCCEEDED(converter->UnEscapeURIForUI(charset, temp,
unicodeRef))) {
mLocationInfo.mHash.Assign('#');
mLocationInfo.mHash.Append(NS_ConvertUTF16toUTF8(unicodeRef));
}
}
if (mLocationInfo.mHash.IsEmpty()) {
mLocationInfo.mHash.Assign('#');
mLocationInfo.mHash.Append(temp);

View File

@ -210,12 +210,6 @@ pref("dom.keyboardevent.code.enabled", true);
// even if this is true).
pref("dom.keyboardevent.dispatch_during_composition", false);
// Whether URL,Location,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
// significantly increase the number of compartments in the system.

View File

@ -744,13 +744,8 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
// #ref
if (mRef.mLen >= 0) {
if (nsContentUtils::EncodeDecodeURLHash()) {
approxLen += 1 + encoder.EncodeSegmentCount(spec, mRef, esc_Ref,
encRef, useEncRef);
} else {
approxLen += 1 + mRef.mLen;
useEncRef = false;
}
approxLen += 1 + encoder.EncodeSegmentCount(spec, mRef, esc_Ref,
encRef, useEncRef);
}
}
@ -2983,16 +2978,14 @@ nsStandardURL::SetRef(const nsACString &input)
// If precent encoding is necessary, `ref` will point to `buf`'s content.
// `buf` needs to outlive any use of the `ref` pointer.
nsAutoCString buf;
if (nsContentUtils::EncodeDecodeURLHash()) {
// encode ref if necessary
bool encoded;
GET_SEGMENT_ENCODER(encoder);
encoder.EncodeSegmentCount(ref, URLSegment(0, refLen), esc_Ref,
buf, encoded);
if (encoded) {
ref = buf.get();
refLen = buf.Length();
}
// encode ref if necessary
bool encoded;
GET_SEGMENT_ENCODER(encoder);
encoder.EncodeSegmentCount(ref, URLSegment(0, refLen), esc_Ref,
buf, encoded);
if (encoded) {
ref = buf.get();
refLen = buf.Length();
}
int32_t shift = ReplaceSegment(mRef.mPos, mRef.mLen, ref, refLen);