summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonchild <wolfbeast@users.noreply.github.com>2017-08-28 10:02:42 +0200
committerGitHub <noreply@github.com>2017-08-28 10:02:42 +0200
commit391d8723131d5225787b03a1f0945b552f484ae1 (patch)
tree0cc3c5a56f1ad6948cab78748952371d95081264
parent9ab602aa7102cabd029691d8f972b3075dc4693f (diff)
parentefb57c3d1e95d442228128df7a069ced0992d076 (diff)
downloadpalemoon-gre-391d8723131d5225787b03a1f0945b552f484ae1.tar.gz
Merge pull request #1312 from adeshkp/patch-3
Be more liberal in matching a URL in the selected text
-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) {