Skip to content

Commit 3650d1d

Browse files
committed
Bug 1121903 - Use encodeURIComponent for keyword url encoding. r=mak
Differential Revision: https://phabricator.services.mozilla.com/D181697
1 parent c16a1fe commit 3650d1d

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

browser/actors/ContextMenuChild.sys.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export class ContextMenuChild extends JSWindowActorChild {
205205
return escape(aName + "=" + aValue);
206206
}
207207

208-
return escape(aName) + "=" + escape(aValue);
208+
return encodeURIComponent(aName) + "=" + encodeURIComponent(aValue);
209209
}
210210
let formData = new this.contentWindow.FormData(node.form);
211211
formData.delete(node.name);

browser/components/search/test/browser/browser_addKeywordSearch.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ var testData = [
1111
action: "http://example.com/search?oe=utf-8",
1212
param: "q",
1313
},
14+
{
15+
desc: "With Unicode Query String",
16+
action: "http://example.com/searching",
17+
param: "q",
18+
testHiddenUnicode: true,
19+
},
1420
];
1521

1622
add_task(async function () {
@@ -20,7 +26,7 @@ add_task(async function () {
2026

2127
let count = 0;
2228
for (let method of ["GET", "POST"]) {
23-
for (let { desc, action, param } of testData) {
29+
for (let { desc, action, param, testHiddenUnicode = false } of testData) {
2430
info(`Running ${method} keyword test '${desc}'`);
2531
let id = `keyword-form-${count++}`;
2632
let contextMenu = document.getElementById("contentAreaContextMenu");
@@ -31,7 +37,7 @@ add_task(async function () {
3137

3238
await SpecialPowers.spawn(
3339
tab.linkedBrowser,
34-
[{ action, param, method, id }],
40+
[{ action, param, method, id, testHiddenUnicode }],
3541
async function (args) {
3642
let doc = content.document;
3743
let form = doc.createElement("form");
@@ -42,6 +48,12 @@ add_task(async function () {
4248
element.setAttribute("type", "text");
4349
element.setAttribute("name", args.param);
4450
form.appendChild(element);
51+
if (args.testHiddenUnicode) {
52+
form.insertAdjacentHTML(
53+
"beforeend",
54+
`<input name="utf8✓" type="hidden" value="✓">`
55+
);
56+
}
4557
doc.body.appendChild(form);
4658
}
4759
);
@@ -63,17 +75,31 @@ add_task(async function () {
6375
data.spec.endsWith(`${param}=%s`),
6476
`Check expected url for field named ${param} and action ${action}`
6577
);
78+
if (testHiddenUnicode) {
79+
ok(
80+
data.spec.includes(`utf8%E2%9C%93=%E2%9C%93`),
81+
`Check the unicode param is correctly encoded`
82+
);
83+
}
6684
} else {
6785
is(
6886
data.spec,
6987
url,
7088
`Check expected url for field named ${param} and action ${action}`
7189
);
72-
is(
73-
data.postData,
74-
`${param}%3D%25s`,
75-
`Check expected POST data for field named ${param} and action ${action}`
76-
);
90+
if (testHiddenUnicode) {
91+
is(
92+
data.postData,
93+
`utf8%u2713%3D%u2713&q%3D%25s`,
94+
`Check expected POST data for field named ${param} and action ${action}`
95+
);
96+
} else {
97+
is(
98+
data.postData,
99+
`${param}%3D%25s`,
100+
`Check expected POST data for field named ${param} and action ${action}`
101+
);
102+
}
77103
}
78104

79105
let popupHiddenPromise = BrowserTestUtils.waitForEvent(

0 commit comments

Comments
 (0)