summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src
diff options
context:
space:
mode:
authorMarc Strapetz <marc.strapetz@syntevo.com>2017-12-09 13:23:28 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2017-12-23 21:18:12 +0100
commit8cc783ca7d3180ec8b548dd67743f5fc1e9a6a15 (patch)
treef1ce399b7fe3cdc4a3839dc5626f0188eea0b590 /org.eclipse.jgit/src
parenta107bb18a4460a30675f13c23f9d0f5728ecf0e4 (diff)
downloadjgit-8cc783ca7d3180ec8b548dd67743f5fc1e9a6a15.tar.gz
jgit-8cc783ca7d3180ec8b548dd67743f5fc1e9a6a15.zip
URIish: support for empty ports
Properly parse URLs like "ssh://host:/path" Bug: 519187 Change-Id: I0054868e30509e4ba919444be16c2a20f741545a Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java24
1 files changed, 18 insertions, 6 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
index a41e47ec82..a048fe30f2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
@@ -95,7 +95,7 @@ public class URIish implements Serializable {
* Part of a pattern which matches the optional port part of URIs. Defines
* one capturing group containing the port without the preceding colon.
*/
- private static final String OPT_PORT_P = "(?::(\\d+))?"; //$NON-NLS-1$
+ private static final String OPT_PORT_P = "(?::(\\d*))?"; //$NON-NLS-1$
/**
* Part of a pattern which matches the ~username part (e.g. /~root in
@@ -224,11 +224,23 @@ public class URIish implements Serializable {
scheme = matcher.group(1);
user = unescape(matcher.group(2));
pass = unescape(matcher.group(3));
- host = unescape(matcher.group(4));
- if (matcher.group(5) != null)
- port = Integer.parseInt(matcher.group(5));
- rawPath = cleanLeadingSlashes(
- n2e(matcher.group(6)) + n2e(matcher.group(7)), scheme);
+ // empty ports are in general allowed, except for URLs like
+ // file://D:/path for which it is more desirable to parse with
+ // host=null and path=D:/path
+ String portString = matcher.group(5);
+ if ("file".equals(scheme) && "".equals(portString)) { //$NON-NLS-1$ //$NON-NLS-2$
+ rawPath = cleanLeadingSlashes(
+ n2e(matcher.group(4)) + ":" + portString //$NON-NLS-1$
+ + n2e(matcher.group(6)) + n2e(matcher.group(7)),
+ scheme);
+ } else {
+ host = unescape(matcher.group(4));
+ if (portString != null && portString.length() > 0) {
+ port = Integer.parseInt(portString);
+ }
+ rawPath = cleanLeadingSlashes(
+ n2e(matcher.group(6)) + n2e(matcher.group(7)), scheme);
+ }
path = unescape(rawPath);
return;
}