Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 0b5cb9f

Browse files
japodGerrit Code Review
authored andcommitted
Merge "JERSEY-2753: "UriBuilder should leave relative path relative""
2 parents 5ce6852 + 97d1708 commit 0b5cb9f

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

core-common/src/main/java/org/glassfish/jersey/uri/UriTemplate.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2010-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2015 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -921,7 +921,9 @@ private static String createURIWithStringValues(
921921
sb.append(':');
922922
}
923923

924+
boolean hasAuthority = false;
924925
if (notEmpty(userInfo) || notEmpty(host) || notEmpty(port)) {
926+
hasAuthority = true;
925927
sb.append("//");
926928

927929
if (notEmpty(userInfo)) {
@@ -942,6 +944,7 @@ private static String createURIWithStringValues(
942944
offset, false, mapValues, sb);
943945
}
944946
} else if (notEmpty(authority)) {
947+
hasAuthority = true;
945948
sb.append("//");
946949

947950
offset = createUriComponent(UriComponent.Type.AUTHORITY, authority, values,
@@ -950,7 +953,7 @@ private static String createURIWithStringValues(
950953

951954
if (notEmpty(path) || notEmpty(query) || notEmpty(fragment)) {
952955
// make sure we append at least the root path if only query or fragment is present
953-
if (sb.length() > 0 && (path == null || path.isEmpty() || path.charAt(0) != '/')) {
956+
if (hasAuthority && (path == null || path.isEmpty() || path.charAt(0) != '/')) {
954957
sb.append('/');
955958
}
956959

core-common/src/main/java/org/glassfish/jersey/uri/internal/JerseyUriBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2010-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2015 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -870,7 +870,7 @@ public String toTemplate() {
870870
}
871871

872872
if (path.length() > 0) {
873-
if (sb.length() > 0 && path.charAt(0) != '/') {
873+
if (hasAuthority && path.charAt(0) != '/') {
874874
sb.append("/");
875875
}
876876
sb.append(path);

core-common/src/test/java/org/glassfish/jersey/uri/internal/JerseyUriBuilderTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2011-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2011-2015 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -187,6 +187,16 @@ public void testEmptyUriString() throws URISyntaxException {
187187
// it is not possible to create a java.net.URI from this builder if SSP is empty
188188
}
189189

190+
// Reproducer for JERSEY-2753
191+
@Test
192+
public void testUriBuilderShouldLeaveRelativePathRelative() {
193+
UriBuilder builder = JerseyUriBuilder.fromPath("");
194+
builder.scheme("http");
195+
builder.replacePath("path");
196+
197+
assertEquals("http:path", builder.build().toString());
198+
}
199+
190200
@Test
191201
public void testToTemplate() throws URISyntaxException {
192202
JerseyUriBuilder ub = new JerseyUriBuilder()

0 commit comments

Comments
 (0)