Skip to content

Commit

Permalink
Fix a bug where an empty query is translated into /
Browse files Browse the repository at this point in the history
  • Loading branch information
trustin committed Apr 5, 2023
1 parent b1f64f6 commit 72f1512
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ private static RequestTarget slowForClient(String reqTarget,
// path?query
if ((query = decodePercentsAndEncodeToUtf8(
reqTarget, queryPos + 1, reqTarget.length(),
ComponentType.QUERY, SLASH_BYTES)) == null) {
ComponentType.QUERY, EMPTY_BYTES)) == null) {
return null;
}
fragment = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,16 @@ void clientShouldRejectInvalidSchemeOrAuthority() {
assertRejected(forClient("http:///")); // empty authority
}

@ParameterizedTest
@EnumSource(Mode.class)
void shouldYieldEmptyStringForEmptyQueryAndFragment(Mode mode) {
assertAccepted(parse(mode, "/?"), "/", "");
if (mode == Mode.CLIENT) {
assertAccepted(forClient("/#"), "/", null, "");
assertAccepted(forClient("/?#"), "/", "", "");
}
}

@Test
void testToString() {
assertThat(forServer("/")).asString().isEqualTo("/");
Expand Down

0 comments on commit 72f1512

Please sign in to comment.