jetty / jetty.project

Eclipse Jetty® - Web Container & Clients - supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more
https://eclipse.dev/jetty
Other
3.85k stars 1.91k forks source link

Parsing URI with HttpUri.from(String uri) throws "IllegalArgumentException: Bad authority" when path is empty #12404

Open jomapp opened 1 day ago

jomapp commented 1 day ago

Jetty version(s) 12.0.14

Jetty Environment core

Java version/vendor (use: java -version) 21.0.2+13-LTS

OS type/version Ubuntu 22.04

Description

Parsing an URI with HttpUri.from(String uri) throws an "IllegalArgumentException: Bad authority", when the path is empty (path-empty), but a query is present in the URI. E.g. "http://example.com?id=123". According to https://datatracker.ietf.org/doc/html/rfc3986#section-3.3 an empty path followed by a query section is valid though.

Thanks for looking into this issue!

How to reproduce?

joakime commented 1 day ago

Noting that standard java URI supports this.

|  Welcome to JShell -- Version 17.0.11
|  For an introduction type: /help intro

jshell> var uri = new URI("http://example.com?id=123")
uri ==> http://example.com?id=123

jshell> uri.getPath()
$2 ==> ""

jshell> uri.getQuery()
$3 ==> "id=123"

jshell> uri.getAuthority()
$4 ==> "example.com"