@@ -88,6 +88,8 @@ public static URIBuilder loopbackAddress() {
88
88
private String fragment ;
89
89
private String encodedFragment ;
90
90
91
+ private boolean plusAsBlank ;
92
+
91
93
/**
92
94
* Constructs an empty instance.
93
95
*/
@@ -192,6 +194,33 @@ public Charset getCharset() {
192
194
return charset ;
193
195
}
194
196
197
+ /**
198
+ * Sets whether the plus sign ('+') should be interpreted as a blank space (' ') when parsing
199
+ * the query parameters of the URI.
200
+ * <p>
201
+ * In HTTP URLs, query strings may contain spaces encoded as '+' characters or as '%20'.
202
+ * This flag controls whether '+' is interpreted as a space or remains as a plus sign.
203
+ * </p>
204
+ *
205
+ * <p>
206
+ * If the query string was already set, calling this method will re-parse the query
207
+ * using the updated flag. This ensures that the query parameters are processed correctly
208
+ * based on the specified interpretation of the '+' character.
209
+ * </p>
210
+ *
211
+ * @param plusAsBlank {@code true} to interpret '+' as a space, {@code false} to keep '+' as a literal plus sign.
212
+ * @return this {@link URIBuilder} instance for method chaining.
213
+ * @since 5.4
214
+ */
215
+ public URIBuilder setPlusAsBlank (final boolean plusAsBlank ) {
216
+ this .plusAsBlank = plusAsBlank ;
217
+ // Re-parse the query string using the updated flag
218
+ if (this .encodedQuery != null ) {
219
+ this .queryParams = parseQuery (this .encodedQuery , this .charset , this .plusAsBlank );
220
+ }
221
+ return this ;
222
+ }
223
+
195
224
private static final char QUERY_PARAM_SEPARATOR = '&' ;
196
225
private static final char PARAM_VALUE_SEPARATOR = '=' ;
197
226
private static final char PATH_SEPARATOR = '/' ;
@@ -402,7 +431,7 @@ private void digestURI(final URI uri, final Charset charset) {
402
431
this .pathSegments = parsePath (uri .getRawPath (), charset );
403
432
this .pathRootless = uri .getRawPath () == null || !uri .getRawPath ().startsWith ("/" );
404
433
this .encodedQuery = uri .getRawQuery ();
405
- this .queryParams = parseQuery (uri .getRawQuery (), charset , false );
434
+ this .queryParams = parseQuery (uri .getRawQuery (), charset , this . plusAsBlank );
406
435
this .encodedFragment = uri .getRawFragment ();
407
436
this .fragment = uri .getFragment ();
408
437
this .charset = charset ;
0 commit comments