From 78a67925e8c2c92edc2a2fa906fc4d4a1d410608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Prante?= Date: Tue, 8 Aug 2023 13:45:22 +0200 Subject: [PATCH] fix URL scheme colon parsing --- gradle.properties | 2 +- net/src/main/java/org/xbib/net/URLParser.java | 9 +++++++-- net/src/test/java/org/xbib/net/URLParserTest.java | 9 +++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 4f31883..693c899 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group = org.xbib name = net -version = 3.3.1 +version = 3.3.2 org.gradle.warning.mode = ALL diff --git a/net/src/main/java/org/xbib/net/URLParser.java b/net/src/main/java/org/xbib/net/URLParser.java index 5786284..fb36cbd 100644 --- a/net/src/main/java/org/xbib/net/URLParser.java +++ b/net/src/main/java/org/xbib/net/URLParser.java @@ -72,14 +72,19 @@ public class URLParser { } String parseScheme(URLBuilder builder, String input) { - Pair p = URL.indexOf(URL.COLON_CHAR, input); + // there may be colons in query params, so + // check if input contains query (question mark) and save query for later return + int pos = input.indexOf(URL.QUESTION_CHAR); + String string = pos > 0 ? input.substring(0, pos) : input; + String query = pos > 0 ? input.substring(pos) : ""; + Pair p = URL.indexOf(URL.COLON_CHAR, string); if (p.getValue() == null) { return input; } if (!URL.isNullOrEmpty(p.getKey())) { builder.scheme(p.getKey()); } - return p.getValue(); + return p.getValue() + query; } String parseUserInfo(URLBuilder builder, String input) diff --git a/net/src/test/java/org/xbib/net/URLParserTest.java b/net/src/test/java/org/xbib/net/URLParserTest.java index db59182..fc4b6b3 100644 --- a/net/src/test/java/org/xbib/net/URLParserTest.java +++ b/net/src/test/java/org/xbib/net/URLParserTest.java @@ -486,6 +486,15 @@ class URLParserTest { }); } + @Test + void testUrlWithUnencodedUrlAsParam() { + URL url = URL.from("/path?a=http://example.com"); + Parameter queryParameters = url.getQueryParams(); + // %EF%BF%B = 0xFFFD UNICODE REPLACEMENT CHARACTER + assertEquals("/path", url.getPath()); + assertEquals("[a=http://example.com]", queryParameters.toString()); + } + private void assertUrlCompatibility(String url) throws Exception { String s = URL.from(url).toExternalForm(); assertEquals(s, URL.from(s).toExternalForm());