Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2021-06-10 09:13:02 +0000
committerMickael Istria2021-06-10 17:02:19 +0000
commitb86fe7cd8bf0a0258dcbfe694061d7b5fbe3791b (patch)
tree130f5a266c8d501248f751f4e9a9a2c8f189ed24
parentb772e2ab61d9a0ef9ea628849cb8d228a07e68cb (diff)
downloadeclipse.platform.text-b86fe7cd8bf0a0258dcbfe694061d7b5fbe3791b.tar.gz
eclipse.platform.text-b86fe7cd8bf0a0258dcbfe694061d7b5fbe3791b.tar.xz
eclipse.platform.text-b86fe7cd8bf0a0258dcbfe694061d7b5fbe3791b.zip
Bug 483858 - Handle URL prefixes in URLHyperlinkDetector
Detect quotes around URLs with prefixes to make sure we don't include the closing quote in the link. Change-Id: I565dfb54ac9e7017b8f5fc2a841f2b5a3c5a4905 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch> Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.text/+/181768 Tested-by: Platform Bot <platform-bot@eclipse.org> Reviewed-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java2
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/hyperlink/URLHyperlinkDetector.java15
2 files changed, 16 insertions, 1 deletions
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java
index a56d083ed1f..78acc4d47b8 100644
--- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java
@@ -415,6 +415,8 @@ public class TextViewerTest {
checkHyperlink(textViewer, 3, "https://foo bar", "[https://foo]");
checkHyperlink(textViewer, 15, "https:// foo https://bar bar", "[https://bar]");
checkHyperlink(textViewer, 24, "https:// foo https://bar bar", "[https://bar]");
+ checkHyperlink(textViewer, 15, "<a href=\"test:https://bugs.eclipse.org/bugs\"></a>", "[https://bugs.eclipse.org/bugs]");
+ checkHyperlink(textViewer, 19, "<a href=\"scm:git:https://bugs.eclipse.org/bugs\"></a>", "[https://bugs.eclipse.org/bugs]");
} finally {
shell.dispose();
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/hyperlink/URLHyperlinkDetector.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/hyperlink/URLHyperlinkDetector.java
index 5da9cfa1b66..6221db3548d 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/hyperlink/URLHyperlinkDetector.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/hyperlink/URLHyperlinkDetector.java
@@ -95,7 +95,20 @@ public class URLHyperlinkDetector extends AbstractHyperlinkDetector {
quote= ch;
} while (Character.isUnicodeIdentifierStart(ch));
urlOffsetInLine++;
-
+ // Handle prefixes like "scm:https://foo": scan further back
+ if (ch == ':') {
+ int i= urlOffsetInLine - 1;
+ while (i >= 0) {
+ ch= line.charAt(i--);
+ if (ch == '"' || ch == '\'') {
+ quote= ch;
+ break;
+ }
+ if (ch != ':' && !Character.isUnicodeIdentifierStart(ch)) {
+ break;
+ }
+ }
+ }
// Right to "://"
int end= urlSeparatorOffset + 3;
while (end < lineEnd && STOP_CHARACTERS.indexOf(line.charAt(end)) < 0) {

Back to the top