diff --git a/bundles/org.openhab.binding.http/README.md b/bundles/org.openhab.binding.http/README.md index 720ab6dd84d76..9313712a24b0f 100644 --- a/bundles/org.openhab.binding.http/README.md +++ b/bundles/org.openhab.binding.http/README.md @@ -37,9 +37,9 @@ Authentication might fail if redirections are involved as headers are stripper p _Note:_ If you rate-limit requests by using the `delay` parameter you have to make sure that the time between two refreshes is larger than the time needed for one refresh cycle. -**Attention:** `baseUrl` (and `stateExtension`/`commandExtension`) should not use escaping (e.g. `%22` instead of `"` or `%2c` instead of `,`). +**Attention:** `baseUrl` (and `stateExtension`/`commandExtension`) don't normally require percent encoding (e.g. `%22` instead of `"` or `%2C` instead of `,`). URLs are properly escaped by the binding itself before the request is sent. -Using escaped strings in URL parameters may lead to problems with the formatting (see below). +When automatic encoding is not possible (e.g. because you need to include an encoded `=` or `&` in the query string) you can use manual encoding with a doubled `%` (`%%3D` instead of `=`). ## Channels diff --git a/bundles/org.openhab.binding.http/src/main/java/org/openhab/binding/http/internal/Util.java b/bundles/org.openhab.binding.http/src/main/java/org/openhab/binding/http/internal/Util.java index 2c490ba5d5a71..adad2a3d50c91 100644 --- a/bundles/org.openhab.binding.http/src/main/java/org/openhab/binding/http/internal/Util.java +++ b/bundles/org.openhab.binding.http/src/main/java/org/openhab/binding/http/internal/Util.java @@ -66,7 +66,7 @@ public static URI uriFromString(String s) throws MalformedURLException, URISynta URL url = new URL(s); URI uri = new URI(url.getProtocol(), url.getUserInfo(), IDN.toASCII(url.getHost()), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); - return URI.create(uri.toASCIIString().replace("+", "%2B")); + return URI.create(uri.toASCIIString().replace("+", "%2B").replace("%25%25", "%")); } /** diff --git a/bundles/org.openhab.binding.http/src/test/java/org/openhab/binding/http/UtilTest.java b/bundles/org.openhab.binding.http/src/test/java/org/openhab/binding/http/UtilTest.java index b5a8d3e40a1bd..b87e499f67c25 100644 --- a/bundles/org.openhab.binding.http/src/test/java/org/openhab/binding/http/UtilTest.java +++ b/bundles/org.openhab.binding.http/src/test/java/org/openhab/binding/http/UtilTest.java @@ -69,9 +69,9 @@ public void uriPlusInQueryEncodeTest() throws MalformedURLException, URISyntaxEx @Test public void uriAlreadyPartlyEscapedTest() throws MalformedURLException, URISyntaxException { - String s = "https://foo.bar/zzl.html?p=field%2Bvalue&foostatus=This is a test String&date=2024- 07-01"; + String s = "https://foo.bar/zzl.html?p=field%%2Bvalue&foostatus=This is a test String&date=2024- 07-01"; assertEquals( - "https://foo.bar/zzl.html?p=field%252Bvalue&foostatus=This%20is%20a%20test%20String&date=2024-%20%2007-01", + "https://foo.bar/zzl.html?p=field%2Bvalue&foostatus=This%20is%20a%20test%20String&date=2024-%20%2007-01", Util.uriFromString(s).toString()); }