Bug 1042521 - Use original input when calling KeywordToURI and do not trim the input before calling urifixup in tests. r=Gijs

This commit is contained in:
Alex Bardas 2014-08-29 11:13:00 +02:00
parent 4ed3b76f10
commit d956f98bcb
2 changed files with 17 additions and 5 deletions

View File

@ -142,10 +142,11 @@ nsDefaultURIFixup::GetFixupURIInfo(const nsACString& aStringURI, uint32_t aFixup
nsresult rv;
nsAutoCString uriString(aStringURI);
uriString.Trim(" "); // Cleanup the empty spaces that might be on each end.
// Eliminate embedded newlines, which single-line text fields now allow:
uriString.StripChars("\r\n");
// Cleanup the empty spaces that might be on each end:
uriString.Trim(" ");
NS_ENSURE_TRUE(!uriString.IsEmpty(), NS_ERROR_FAILURE);
@ -950,7 +951,7 @@ void nsDefaultURIFixup::KeywordURIFixup(const nsACString & aURIString,
(spaceLoc < qMarkLoc || quoteLoc < qMarkLoc)) ||
qMarkLoc == 0)
{
rv = KeywordToURI(aURIString, aPostData,
rv = KeywordToURI(aFixupInfo->mOriginalInput, aPostData,
getter_AddRefs(aFixupInfo->mPreferredURI));
if (NS_SUCCEEDED(rv) && aFixupInfo->mPreferredURI)
{

View File

@ -60,6 +60,14 @@ let testcases = [
[".test", "http://.test/", "http://www..test/", true, true],
["mozilla is amazing", null, null, true, true],
["mozilla ", "http://mozilla/", "http://www.mozilla.com/", true, true],
[" mozilla ", "http://mozilla/", "http://www.mozilla.com/", true, true],
["mozilla \\", null, null, true, true],
["mozilla \\ foo.txt", null, null, true, true],
["mozilla \\\r foo.txt", null, null, true, true],
["mozilla\n", "http://mozilla/", "http://www.mozilla.com/", true, true],
["mozilla \r\n", "http://mozilla/", "http://www.mozilla.com/", true, true],
["moz\r\nfirefox\nos\r", "http://mozfirefoxos/", "http://www.mozfirefoxos.com/", true, true],
["moz\r\n firefox\n", null, null, true, true],
["", null, null, true, true],
["[]", null, null, true, true]
];
@ -74,10 +82,13 @@ if (Services.appinfo.OS.toLowerCase().startsWith("win")) {
testcases.push(["mozilla\\", "http://mozilla\\/", "http://www.mozilla/", true, true]);
}
function sanitize(input) {
return input.replace(/\r|\n/g, "").trim();
}
function run_test() {
for (let [testInput, expectedFixedURI, alternativeURI,
expectKeywordLookup, expectProtocolChange] of testcases) {
testInput = testInput.trim();
for (let flags of flagInputs) {
let info;
let fixupURIOnly = null;
@ -121,7 +132,7 @@ function run_test() {
// Check the preferred URI
if (couldDoKeywordLookup && expectKeywordLookup) {
let urlparamInput = encodeURIComponent(testInput).replace("%20", "+", "g");
let urlparamInput = encodeURIComponent(sanitize(testInput)).replace("%20", "+", "g");
let searchURL = kSearchEngineURL.replace("{searchTerms}", urlparamInput);
do_check_eq(info.preferredURI.spec, searchURL);
} else {
@ -129,7 +140,7 @@ function run_test() {
// the fixed URI should be preferred:
do_check_eq(info.preferredURI.spec, info.fixedURI.spec);
}
do_check_eq(testInput, info.originalInput);
do_check_eq(sanitize(testInput), info.originalInput);
}
}
}