Hi,

This is my first email to the list, so I hope I will not miss something or do something wrong. I'm writing here instead of reporting a bug directly, mainly because I'm not sure if I can even register in the bug tracker, so apologies if that was the expected way to go.

Cutting to the chase, I believe there is a bug in the UriBuilderImpl. Specifically, when an instance of the class is created through the '.fromURI' method, and the provided URI does not start with a "/" (i.e. it has no schema and authority and its path is not absolute), UriBuilderImpl assumes incorrectly that the URI is non-hierarchical and therefore the '.build()' method will always return the provided URI without modification, regardless of which edit methods (e.g. "queryParam", "path", etc.) are called on the instance.

In order to illustrate what I mean, I created a very simple program (attached). I compiled it with:

   javac -cp '.:<path_to_the_jar>/javax.ws.rs-api-2.0.1.jar' UriBuilderBug.java

and runned it with:

   java -cp 
'.:/<path_to_the_jar>/javax.ws.rs-api-2.0.1.jar:<path_to_the_jar2>/cxf-rt-frontend-jaxrs-3.1.11.jar:<path_to_the_jar3>/cxf-core-3.1.11.jar'
 UriBuilderBug

The RFC-3986, in its section 4.2 <https://tools.ietf.org/html/rfc3986#section-4.2> [1] defines the syntax for valid relative URI references and explicitly allows references without schema or authority that do *not* start with a forward slash. Perhaps part of the confusion comes from the fact that the ABNF defining the relative references is as follows:

   relative-part = "//" authority path-abempty
                  / path-absolute
                  / path-noscheme
                  / path-empty

, where the "/" symbol representing the different alternatives can be easily mistaken for a literal "/" in the URI itself.

So that's it. Thanks for reading till here. Please let know your opinions about this and, if I'm right, it would be great to get it fixed soon. If something is not clear or you have any questions, I'm willing to answer them. If there's a reason for the current behaviour, or if I am incorrectly interpreting the standard, I'd also be very glad to know.

Best regards
--
Rubén Pérez Vázquez

*Universität zu Köln*
/Regionales Rechenzentrum (RRZK)/
Weyertal 121, Raum 4.05
D-50931 Köln
✆: +49-221-470-89603

[1] https://tools.ietf.org/html/rfc3986#section-4.2
import java.net.URI;
import java.net.URISyntaxException;
import javax.ws.rs.core.UriBuilder;

public class UriBuilderBug {

    public static void main (String[] args) throws URISyntaxException {

	UriBuilder builder = UriBuilder.fromUri("relative/uri?with=query");
	System.out.println("Original URI: " + builder.build().toString());
	
	builder.queryParam("extra", "query");
	System.out.println("With extra query: " + builder.build().toString());

	builder.replacePath("/new/absolute/path");
	System.out.println("With new absolute path: " + builder.build().toString());

	System.out.println("==========================================");

	builder = UriBuilder.fromUri("/absolute/uri?with=query");
	System.out.println("Original URI: " + builder.build().toString());

	builder.queryParam("extra", "query");
	System.out.println("With extra query: " + builder.build().toString());

	builder.replacePath("/new/absolute/path");
	System.out.println("With new absolute path: " + builder.build().toString());

	builder.replacePath("new/relative/path");
	System.out.println("With new relative path: " + builder.build().toString());

	builder.queryParam("anotherquery", "true");
	System.out.println("With new yet another query parameter: " + builder.build().toString());

    }
}

Reply via email to