summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--browser/base/content/nsContextMenu.js46
1 files changed, 6 insertions, 40 deletions
diff --git a/browser/base/content/nsContextMenu.js b/browser/base/content/nsContextMenu.js
index 0f8a2cd33..56880ac87 100644
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -87,46 +87,12 @@ nsContextMenu.prototype = {
} catch (ex) {}
}
// Check if this could be a valid url, just missing the protocol.
- else if (/^(?:[a-z\d-]+\.)+[a-z]+$/i.test(linkText)) {
- // Now let's see if this is an intentional link selection. Our guess is
- // based on whether the selection begins/ends with whitespace or is
- // preceded/followed by a non-word character.
-
- // selection.toString() trims trailing whitespace, so we look for
- // that explicitly in the first and last ranges.
- let beginRange = selection.getRangeAt(0);
- let delimitedAtStart = /^\s/.test(beginRange);
- if (!delimitedAtStart) {
- let container = beginRange.startContainer;
- let offset = beginRange.startOffset;
- if (container.nodeType == Node.TEXT_NODE && offset > 0)
- delimitedAtStart = /\W/.test(container.textContent[offset - 1]);
- else
- delimitedAtStart = true;
- }
-
- let delimitedAtEnd = false;
- if (delimitedAtStart) {
- let endRange = selection.getRangeAt(selection.rangeCount - 1);
- delimitedAtEnd = /\s$/.test(endRange);
- if (!delimitedAtEnd) {
- let container = endRange.endContainer;
- let offset = endRange.endOffset;
- if (container.nodeType == Node.TEXT_NODE &&
- offset < container.textContent.length)
- delimitedAtEnd = /\W/.test(container.textContent[offset]);
- else
- delimitedAtEnd = true;
- }
- }
-
- if (delimitedAtStart && delimitedAtEnd) {
- let uriFixup = Cc["@mozilla.org/docshell/urifixup;1"]
- .getService(Ci.nsIURIFixup);
- try {
- uri = uriFixup.createFixupURI(linkText, uriFixup.FIXUP_FLAG_NONE);
- } catch (ex) {}
- }
+ else if (/^[-a-z\d\.]+\.[-a-z\d]{2,}[-_=~:#%&\?\w\/\.]*$/i.test(linkText)) {
+ let uriFixup = Cc["@mozilla.org/docshell/urifixup;1"]
+ .getService(Ci.nsIURIFixup);
+ try {
+ uri = uriFixup.createFixupURI(linkText, uriFixup.FIXUP_FLAG_NONE);
+ } catch (ex) {}
}
if (uri && uri.host) {