]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20532 allow encoded forward slashes in URLs
authorAurelien Poscia <aurelien.poscia@sonarsource.com>
Thu, 28 Sep 2023 09:39:53 +0000 (11:39 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 28 Sep 2023 20:03:12 +0000 (20:03 +0000)
server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/config/CommonWebConfig.java
server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/config/CommonWebConfigTest.java [new file with mode: 0644]

index 8c6f520197eb1ed0d2f51829a2eb10b6376548fd..e74f810cfc4c330422c98273561c6f33dfdfb0c7 100644 (file)
@@ -31,12 +31,23 @@ import org.springframework.context.annotation.PropertySource;
 import org.springframework.http.MediaType;
 import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.util.UrlPathHelper;
 
 @Configuration
 @EnableWebMvc
 @ComponentScan(basePackages = {"org.springdoc"})
 @PropertySource("classpath:springdoc.properties")
-public class CommonWebConfig {
+public class CommonWebConfig implements WebMvcConfigurer {
+
+  @Override
+  public void configurePathMatch(PathMatchConfigurer configurer) {
+    UrlPathHelper urlPathHelper = new UrlPathHelper();
+    urlPathHelper.setUrlDecode(false);
+    configurer.setUrlPathHelper(urlPathHelper);
+  }
+
   @Bean
   public LocalValidatorFactoryBean validator() {
     return new LocalValidatorFactoryBean();
diff --git a/server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/config/CommonWebConfigTest.java b/server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/config/CommonWebConfigTest.java
new file mode 100644 (file)
index 0000000..b295b12
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.v2.config;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
+import org.springframework.web.util.UrlPathHelper;
+
+import static java.util.Objects.requireNonNull;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+@RunWith(MockitoJUnitRunner.class)
+public class CommonWebConfigTest {
+
+  @Test
+  public void configurePathMatch_shouldDisableUrlDecode() {
+    CommonWebConfig commonWebConfig = new CommonWebConfig();
+    PathMatchConfigurer pathMatchConfigurer = new PathMatchConfigurer();
+    commonWebConfig.configurePathMatch(pathMatchConfigurer);
+
+    UrlPathHelper actualUrlPathHelper = requireNonNull(pathMatchConfigurer.getUrlPathHelper());
+
+    assertThat(actualUrlPathHelper.isUrlDecode()).isFalse();
+  }
+
+}