From 130c447b05766d2bf5082b8d56fd186c5bf192cf Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Mon, 12 Nov 2012 11:21:07 +0100 Subject: [PATCH] SONAR-3951 Encode "s" url parameter for resources/search service --- .../org/sonar/wsclient/services/ResourceSearchQuery.java | 5 ++--- .../sonar/wsclient/services/ResourceSearchQueryTest.java | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ResourceSearchQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ResourceSearchQuery.java index aae35d9f2e0..8648524329c 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ResourceSearchQuery.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ResourceSearchQuery.java @@ -75,9 +75,8 @@ public class ResourceSearchQuery extends Query { @Override public String getUrl() { StringBuilder url = new StringBuilder(); - url.append("/api/resources/search?s="); - url.append(text); - url.append("&"); + url.append("/api/resources/search?"); + appendUrlParameter(url, "s", text); if (page > 0) { appendUrlParameter(url, "p", page); } diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ResourceSearchQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ResourceSearchQueryTest.java index f789d361819..717c321c702 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ResourceSearchQueryTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ResourceSearchQueryTest.java @@ -33,6 +33,13 @@ public class ResourceSearchQueryTest extends QueryTestCase { assertThat(query.getModelClass().getName(), is(ResourceSearchResult.class.getName())); } + @Test + public void test_encode_url_search_param() { + ResourceSearchQuery query = ResourceSearchQuery.create("commons logging"); + assertThat(query.getUrl(), is("/api/resources/search?s=commons+logging&")); + assertThat(query.getModelClass().getName(), is(ResourceSearchResult.class.getName())); + } + @Test public void test_optional_parameters() { ResourceSearchQuery query = ResourceSearchQuery.create("commons"); -- 2.39.5