Repository navigation
fix: prevent adding query string for empty parameters in router link href - #17290
Conversation
…href When an empty query parameters object is given to a RouterLink the computed href contains an empty query string. This change prevents the addition of the query string to the href attribute when query parameters object is empty. It also fixes parsing to return an empty query parameters object for blank string. Fixes #17287
Sonatype Lift is retiringSonatype Lift will be retiring on Sep 12, 2023, with its analysis stopping on Aug 12, 2023. We understand that this news may come as a disappointment, and Sonatype is committed to helping you transition off it seamlessly. If you’d like to retain your data, please export your issues from the web console. |
|
Kudos, SonarCloud Quality Gate passed!
|
czp13
left a comment
There was a problem hiding this comment.
Two fixes were made here.
Copying this from the related issue:
- QueryParameters for an empty string should be empty, as reported
- RouterLink should not add query string for empty QueryParameters
Tests are added for multiple cases, imports are good as well.
The only minor thing is that:
Map<String, String> paramMapEmpty = new HashMap<>();
paramMapEmpty.put(" ", "test"); // paramMapEmpty.put("", " "); paramMapEmpty.put(" ", ""); will fail too.
link.setQueryParameters(QueryParameters.simple(paramMapEmpty));
href = link.getHref();
Assert.assertEquals("foo", href);
//Also:
// paramMapEmpty.put("test", " ");
// paramMapEmpty.put("", "test");These cases all will be added. For example:
paramMapEmpty.put("", "test"); -> foo?%20=test
We could handle some of them with a longer condition:
if (queryParameters != null
&& !queryParameters.getParameters().isEmpty()
&& !queryParameters.getParameters().keySet().stream()
.allMatch(String::isBlank)
&& !queryParameters.getParameters().values().stream()
.allMatch(strings -> strings.stream()
.allMatch(String::isBlank))) {
url += '?' + queryParameters.getQueryString();
}Not sure if the above condition is good enough, I think too strict as single query params without value will not be allowed, so maybe we could support this query param:
foo?%20=test
but could support:
foo?test(which is valid as I know)
| url = UrlUtil.encodeURI(url); | ||
| if (queryParameters != null) { | ||
| if (queryParameters != null | ||
| && !queryParameters.getParameters().isEmpty()) { |
There was a problem hiding this comment.
Potentially we could make this condition more strict to exclude this case paramMapEmpty.put("", "test");.
There was a problem hiding this comment.
Actually, nothing prevents you from using blank as a key in a query string.
Taking a look at the specifications, ?=test seems to be a valid query string
There was a problem hiding this comment.
Nice, thanks for checking it. I saw that the empty value is valid:
?value=
But was not sure that the empty key is also valid. Good that you checked it.
I only have one question, but to keep this clean (closed PR). I will follow up in DM about that :).
…href (#17290) When an empty query parameters object is given to a RouterLink the computed href contains an empty query string. This change prevents the addition of the query string to the href attribute when query parameters object is empty. It also fixes parsing to return an empty query parameters object for blank string. Fixes #17287
…href (#17290) When an empty query parameters object is given to a RouterLink the computed href contains an empty query string. This change prevents the addition of the query string to the href attribute when query parameters object is empty. It also fixes parsing to return an empty query parameters object for blank string. Fixes #17287
…href (#17290) When an empty query parameters object is given to a RouterLink the computed href contains an empty query string. This change prevents the addition of the query string to the href attribute when query parameters object is empty. It also fixes parsing to return an empty query parameters object for blank string. Fixes #17287
…href (#17290) (#17363) When an empty query parameters object is given to a RouterLink the computed href contains an empty query string. This change prevents the addition of the query string to the href attribute when query parameters object is empty. It also fixes parsing to return an empty query parameters object for blank string. Fixes #17287 Co-authored-by: Marco Collovati <marco@vaadin.com>
…href (#17290) (#17361) When an empty query parameters object is given to a RouterLink the computed href contains an empty query string. This change prevents the addition of the query string to the href attribute when query parameters object is empty. It also fixes parsing to return an empty query parameters object for blank string. Fixes #17287 Co-authored-by: Marco Collovati <marco@vaadin.com>
…href (#17290) (#17362) When an empty query parameters object is given to a RouterLink the computed href contains an empty query string. This change prevents the addition of the query string to the href attribute when query parameters object is empty. It also fixes parsing to return an empty query parameters object for blank string. Fixes #17287 Co-authored-by: Marco Collovati <marco@vaadin.com>
|
This ticket/PR has been released with Vaadin 24.2.0.alpha6 and is also targeting the upcoming stable 24.2.0 version. |








Description
When an empty query parameters object is given to a RouterLink the computed href contains an empty query string.
This change prevents the addition of the query string to the href attribute when query parameters object is empty. It also fixes parsing to return an empty query parameters object for blank string.
Fixes #17287
Type of change
Checklist
Additional for
Featuretype of change