]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8388 HTTP POST request parameters are handled as UTF-8 by default
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Fri, 27 Jan 2017 15:50:25 +0000 (16:50 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 30 Jan 2017 13:57:14 +0000 (14:57 +0100)
it/it-tests/src/test/java/it/settings/DeprecatedPropertiesWsTest.java
server/sonar-server/src/main/java/org/sonar/server/platform/web/SecurityServletFilter.java
server/sonar-server/src/test/java/org/sonar/server/setting/ws/SetActionTest.java
server/sonar-server/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java
server/sonar-web/src/main/webapp/WEB-INF/web.xml

index c0f431a7e45663b6f9667f1e5ac8b3f70ac1f599..876cfccd071643f7c321410cc0b54e2de1a676fa 100644 (file)
@@ -353,7 +353,7 @@ public class DeprecatedPropertiesWsTest {
       .url(url));
   }
 
-  public static Response call(Request.Builder requestBuilder) {
+  private static Response call(Request.Builder requestBuilder) {
     try {
       requestBuilder.header("Authorization", Credentials.basic("admin", "admin"));
       Response response = new OkHttpClient.Builder()
index c533f7e1ec1c172ed0e65ce884dbf56d81b48890..1ce76a84148259a7dfd36f590aef39c9707ffc67 100644 (file)
@@ -33,7 +33,6 @@ import javax.servlet.http.HttpServletResponse;
 
 /**
  * This servlet filter sets response headers that enable browser protection against several classes if Web attacks.
- * The list of headers is mirrored in environment.rb as a workaround to Rack swallowing the headers..
  */
 public class SecurityServletFilter implements Filter {
 
index 23a37000e5c05fac8d661de7b10485b46c91c0fe..8ab347473f94a4f2acd4f5435badeabd846cbd86 100644 (file)
@@ -374,6 +374,14 @@ public class SetActionTest {
     assertGlobalSetting("my.key", "My Value");
   }
 
+  @Test
+  public void persist_global_setting_with_non_ascii_characters() {
+    callForGlobalSetting("my.key", "fi±∞…");
+
+    assertGlobalSetting("my.key", "fi±∞…");
+    assertThat(settingsChangeNotifier.wasCalled).isTrue();
+  }
+
   @Test
   public void fail_when_no_key() {
     expectedException.expect(IllegalArgumentException.class);
index 61c38d770040b7cc9e4fb348f77789eef06e8608..abbe380e386a9e7756d8d9a81004625b8b64e67d 100644 (file)
@@ -722,6 +722,19 @@ public class ValuesActionTest {
       "sonar.plugin.licenseHash.secured");
   }
 
+  @Test
+  public void return_simple_value_with_non_ascii_characters() throws Exception {
+    setAuthenticatedUser();
+    definitions.addComponent(PropertyDefinition
+      .builder("foo")
+      .build());
+    propertyDb.insertProperties(newGlobalPropertyDto().setKey("foo").setValue("fi±∞…"));
+
+    ValuesWsResponse result = executeRequestForGlobalProperties("foo");
+
+    assertThat(result.getSettings(0).getValue()).isEqualTo("fi±∞…");
+  }
+
   @Test
   public void fail_when_user_has_not_project_browse_permission() throws Exception {
     userSession.login("project-admin").addProjectUuidPermissions(CODEVIEWER, project.uuid());
index 5cc279b60efc11c46e8efa0972404ac847bcb31f..638787dc1f5a1df75713b16b2c14b334fa8ac7b6 100644 (file)
     <filter-name>UserSessionFilter</filter-name>
     <filter-class>org.sonar.server.user.UserSessionFilter</filter-class>
   </filter>
+  <filter>
+    <filter-name>SetCharacterEncodingFilter</filter-name>
+    <filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
+    <init-param>
+      <param-name>encoding</param-name>
+      <param-value>UTF-8</param-value>
+    </init-param>
+  </filter>
   <filter>
     <filter-name>SecurityFilter</filter-name>
     <filter-class>org.sonar.server.platform.web.SecurityServletFilter</filter-class>
   </filter>
 
   <!-- order of execution is important -->
+  <filter-mapping>
+    <filter-name>SetCharacterEncodingFilter</filter-name>
+    <url-pattern>/*</url-pattern>
+  </filter-mapping>
   <filter-mapping>
     <filter-name>RootFilter</filter-name>
     <url-pattern>/*</url-pattern>