UriComponentsBuilder supports query without value

Fix UriComponentsBuilder to support query parameters that do not
include a value without losing '='. The following styles are now
supported:

    http://example.com/foo?bar=baz
    http://example.com/foo?bar=
    http://example.com/foo?bar

Issue: SPR-10215
This commit is contained in:
Phillip Webb
2013-02-11 09:39:51 -08:00
parent f32ce3a613
commit 203b22b246
2 changed files with 27 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,10 +27,12 @@ import org.junit.Test;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.*;
/**
* @author Arjen Poutsma
* @author Phillip Webb
*/
public class UriComponentsBuilderTests {
@@ -312,4 +314,22 @@ public class UriComponentsBuilderTests {
assertEquals("mailto:foo@example.com", result.toUriString());
}
@Test
public void queryParamWithValueWithEquals() throws Exception {
UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://example.com/foo?bar=baz").build();
assertThat(uriComponents.toUriString(), equalTo("http://example.com/foo?bar=baz"));
}
@Test
public void queryParamWithoutValueWithEquals() throws Exception {
UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://example.com/foo?bar=").build();
assertThat(uriComponents.toUriString(), equalTo("http://example.com/foo?bar="));
}
@Test
public void queryParamWithoutValueWithoutEquals() throws Exception {
UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://example.com/foo?bar").build();
assertThat(uriComponents.toUriString(), equalTo("http://example.com/foo?bar"));
}
}