File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
main/java/org/springframework/hateoas
test/java/org/springframework/hateoas Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 3232import org .springframework .hateoas .TemplateVariable .VariableType ;
3333import org .springframework .lang .Nullable ;
3434import org .springframework .util .Assert ;
35+ import org .springframework .util .MultiValueMap ;
3536import org .springframework .util .StringUtils ;
3637import org .springframework .web .util .UriBuilderFactory ;
3738import org .springframework .web .util .UriComponents ;
@@ -177,8 +178,9 @@ public UriTemplate with(TemplateVariables variables) {
177178
178179 for (TemplateVariable variable : variables ) {
179180
181+ MultiValueMap <String , String > parameters = components .getQueryParams ();
180182 boolean isRequestParam = variable .isRequestParameterVariable ();
181- boolean alreadyPresent = components . getQueryParams () .containsKey (variable .getName ());
183+ boolean alreadyPresent = parameters .containsKey (variable .getName ());
182184
183185 if (isRequestParam && alreadyPresent ) {
184186 continue ;
@@ -188,6 +190,11 @@ public UriTemplate with(TemplateVariables variables) {
188190 continue ;
189191 }
190192
193+ // Use request parameter continuation if base contains parameters already
194+ if (!parameters .isEmpty () && variable .getType ().equals (VariableType .REQUEST_PARAM )) {
195+ variable = variable .withType (VariableType .REQUEST_PARAM_CONTINUED );
196+ }
197+
191198 ExpandGroup existing = groups .findLastExpandGroupOfType (variable .getType ());
192199 ExpandGroup group = new ExpandGroup (Collections .singletonList (variable ));
193200
Original file line number Diff line number Diff line change @@ -366,6 +366,15 @@ void expandsCompositePaths() {
366366 assertThat (uri ).isEqualTo (URI .create ("/foo/first/second" ));
367367 }
368368
369+ @ Test // #1696
370+ void adaptsRequestParamVariableToContinuationIfBaseUriContainsParameter () {
371+
372+ UriTemplate template = UriTemplate .of ("/path/{bar}/foo.zip?type=foo" )
373+ .with (new TemplateVariable ("foobar" , VariableType .REQUEST_PARAM ));
374+
375+ assertThat (template .toString ()).isEqualTo ("/path/{bar}/foo.zip?type=foo{&foobar}" );
376+ }
377+
369378 private static void assertVariables (UriTemplate template , TemplateVariable ... variables ) {
370379 assertVariables (template , Arrays .asList (variables ));
371380 }
You can’t perform that action at this time.
0 commit comments