Skip to content

Commit

Permalink
fix StringIndexOutOfBoundsException when path is same webjar. springd…
Browse files Browse the repository at this point in the history
  • Loading branch information
uc4w6c committed May 27, 2023
1 parent 0a4e47e commit 851c394
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public AbstractSwaggerResourceResolver(SwaggerUiConfigProperties swaggerUiConfig
@Nullable
protected String findWebJarResourcePath(String path) {
String webjar = webjar(path);
if (webjar.length() > 0) {
if (webjar.length() > 0 && !path.equals(webjar)) {
String version = swaggerUiConfigProperties.getVersion();
if (version != null) {
String partialPath = path(webjar, path);
Expand Down Expand Up @@ -72,4 +72,4 @@ private String path(String webjar, String path) {
}
return path;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.springdoc.ui;

import java.util.Objects;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springdoc.core.SwaggerUiConfigProperties;

import static org.junit.jupiter.api.Assertions.*;

class AbstractSwaggerResourceResolverTest {
private SwaggerUiConfigProperties swaggerUiConfigProperties;

private AbstractSwaggerResourceResolver abstractSwaggerResourceResolver;

private final String VERSION = "4.18.2";

@BeforeEach
public void setup(){
swaggerUiConfigProperties = new SwaggerUiConfigProperties();
swaggerUiConfigProperties.setVersion(VERSION);
abstractSwaggerResourceResolver = new AbstractSwaggerResourceResolver(swaggerUiConfigProperties);
}

@Test
void findWebJarResourcePath() {
String path = "swagger-ui/swagger-initializer.js";

String actual = abstractSwaggerResourceResolver.findWebJarResourcePath(path);
assertEquals("swagger-ui/4.18.2/swagger-initializer.js", actual);
}

@Test
void returNullWhenPathIsSameAsWebjar() {
String path = "swagger-ui";

String actual = abstractSwaggerResourceResolver.findWebJarResourcePath(path);
assertTrue(Objects.isNull(actual));
}

@Test
void returNullWhenVersionIsNull() {
String path = "swagger-ui/swagger-initializer.js";
swaggerUiConfigProperties.setVersion(null);

String actual = abstractSwaggerResourceResolver.findWebJarResourcePath(path);
assertTrue(Objects.isNull(actual));
}
}

0 comments on commit 851c394

Please sign in to comment.