Skip to content

Commit

Permalink
Bug 1185358: Replace any whitespace chars with space. r=adw
Browse files Browse the repository at this point in the history
  • Loading branch information
Daisuke Akatsuka committed Feb 22, 2021
1 parent 6cb8765 commit feba0e3
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
13 changes: 12 additions & 1 deletion browser/components/urlbar/UrlbarInput.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -3037,7 +3037,18 @@ class UrlbarInput {
}
let oldEnd = oldValue.substring(this.selectionEnd);

let pasteData = UrlbarUtils.stripUnsafeProtocolOnPaste(originalPasteData);
let pasteData = originalPasteData;
try {
Services.uriFixup.getFixupURIInfo(
pasteData,
Ci.nsIURIFixup.FIXUP_FLAG_FIX_SCHEME_TYPOS
);
} catch (e) {
pasteData = pasteData.replace(/\s/g, " ");
}

pasteData = UrlbarUtils.stripUnsafeProtocolOnPaste(pasteData);

if (originalPasteData != pasteData) {
// Unfortunately we're not allowed to set the bits being pasted
// so cancel this event:
Expand Down
1 change: 1 addition & 0 deletions browser/components/urlbar/tests/browser/browser.ini
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ support-files =
searchSuggestionEngine.xml
searchSuggestionEngine.sjs
[browser_pasteAndGo.js]
[browser_paste_multi_lines.js]
[browser_percent_encoded.js]
[browser_placeholder.js]
support-files =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test handling whitespace chars such as "\n”.

const TEST_DATA = [
{
input: "this is a\ntest",
expected: "this is a test",
},
{
input: "this is a\n\ttest",
expected: "this is a test",
},
{
input: "http:\n//\nexample.\ncom",
expected: "http://example.com",
},
{
input: "htp:example.\ncom",
expected: "htp:example.com",
},
{
input: "example.\ncom",
expected: "example.com",
},
{
input: "http://example.com/foo bar/",
expected: "http://example.com/foo bar/",
},
{
input: "javasc\nript:\nalert(1)",
expected: "alert(1)",
},
];

add_task(async function test_paste_multi_lines() {
for (const testData of TEST_DATA) {
gURLBar.value = "";
gURLBar.focus();

await paste(testData.input);

Assert.equal(gURLBar.value, testData.expected, "Pasted value is correct");
}
});

async function paste(input) {
await SimpleTest.promiseClipboardChange(input, () => {
clipboardHelper.copyString(input);
});

document.commandDispatcher
.getControllerForCommand("cmd_paste")
.doCommand("cmd_paste");
}

0 comments on commit feba0e3

Please sign in to comment.