Bug 707567 - prepend http:// to URL copy selection only if at least the full hostname is selected. r=dietrich

This commit is contained in:
Dão Gottwald 2012-01-09 10:53:17 +01:00
parent b031938d0e
commit c7c1004a3d
2 changed files with 25 additions and 4 deletions

View File

@ -43,7 +43,7 @@ var tests = [
},
{
copyVal: "<example.co>m",
copyExpected: "http://example.co"
copyExpected: "example.co"
},
{
copyVal: "e<x>ample.com",
@ -51,7 +51,21 @@ var tests = [
},
{
copyVal: "<e>xample.com",
copyExpected: "http://e"
copyExpected: "e"
},
{
loadURL: "http://example.com/foo",
expectedURL: "example.com/foo",
copyExpected: "http://example.com/foo"
},
{
copyVal: "<example.com>/foo",
copyExpected: "http://example.com"
},
{
copyVal: "<example>.com/foo",
copyExpected: "example"
},
// Test that userPass is stripped out

View File

@ -510,10 +510,17 @@
var inputVal = this.inputField.value;
var selectedVal = inputVal.substring(this.selectionStart, this.selectionEnd);
// If the selection doesn't start at the beginning or URL bar is
// modified, nothing else to do here.
// If the selection doesn't start at the beginning or doesn't span the full domain or
// the URL bar is modified, nothing else to do here.
if (this.selectionStart > 0 || this.valueIsTyped)
return selectedVal;
// The selection doesn't span the full domain if it doesn't contain a slash and is
// followed by some character other than a slash.
if (selectedVal.indexOf("/") == -1) {
let remainder = inputVal.replace(selectedVal, "");
if (remainder != "" && remainder[0] != "/")
return selectedVal;
}
let uriFixup = Cc["@mozilla.org/docshell/urifixup;1"].getService(Ci.nsIURIFixup);