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>
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 a56d083..78acc4d 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 @@
 			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 5da9cfa..6221db3 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 @@
 					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) {