From 213609520351bc26beab887dd7f41f09b0b70d89 Mon Sep 17 00:00:00 2001 From: Christian Halstrick Date: Wed, 6 Oct 2010 15:43:42 +0200 Subject: [PATCH] Fixed URI regexp regarding user/password part The regular expression which should handle the user/password part in an URI was potentially processing too many chars. This led to problems when user/pwd and port was specified Change-Id: I87db02494c4b367283e1d00437b1c06d2c8fdd28 Signed-off-by: Christian Halstrick Signed-off-by: Matthias Sohn --- .../eclipse/jgit/transport/URIishTest.java | 23 +++++++++++++++++++ .../org/eclipse/jgit/transport/URIish.java | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java index 9c4c11cd2..88651b75e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java @@ -424,4 +424,27 @@ public void testGetValidWithSlashesDotGitSlashHumanishName() assertEquals("c", humanishName); } + public void testUserPasswordAndPort() throws URISyntaxException { + String str = "http://user:secret@host.xy:80/some/path"; + URIish u = new URIish(str); + assertEquals("http", u.getScheme()); + assertTrue(u.isRemote()); + assertEquals("/some/path", u.getPath()); + assertEquals("host.xy", u.getHost()); + assertEquals(80, u.getPort()); + assertEquals("user", u.getUser()); + assertEquals("secret", u.getPass()); + assertEquals(u, new URIish(str)); + + str = "http://user:secret@pass@host.xy:80/some/path"; + u = new URIish(str); + assertEquals("http", u.getScheme()); + assertTrue(u.isRemote()); + assertEquals("/some/path", u.getPath()); + assertEquals("host.xy", u.getHost()); + assertEquals(80, u.getPort()); + assertEquals("user", u.getUser()); + assertEquals("secret@pass", u.getPass()); + assertEquals(u, new URIish(str)); + } } 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 44ba632d1..3c044fe67 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java @@ -2,6 +2,7 @@ * Copyright (C) 2009, Mykola Nikishov * Copyright (C) 2008, Robin Rosenberg * Copyright (C) 2008, Shawn O. Pearce + * Copyright (C) 2010, Christian Halstrick * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -74,7 +75,7 @@ public class URIish implements Serializable { * capturing groups: the first containing the user and the second containing * the password */ - private static final String OPT_USER_PWD_P = "(?:([^/]+?)(?::([^/]+?))?@)?"; + private static final String OPT_USER_PWD_P = "(?:([^/:@]+)(?::([^/]+))?@)?"; /** * Part of a pattern which matches the optional host part of URIs. Defines