mirror of
https://gitee.com/dcren/initializr.git
synced 2025-07-15 22:55:33 +08:00
Fix generation of filename with empty artifactId
Closes gh-831
This commit is contained in:
parent
f18c08f88f
commit
24887e1ab3
@ -61,6 +61,7 @@ import org.springframework.http.ResponseEntity.BodyBuilder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.DigestUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -320,8 +321,11 @@ public class MainController extends AbstractInitializrController {
|
||||
"application/x-compress");
|
||||
}
|
||||
|
||||
private static String generateFileName(ProjectRequest request, String extension) {
|
||||
String tmp = request.getArtifactId().replaceAll(" ", "_");
|
||||
private String generateFileName(ProjectRequest request, String extension) {
|
||||
String candidate = (StringUtils.hasText(request.getArtifactId())
|
||||
? request.getArtifactId()
|
||||
: this.metadataProvider.get().getArtifactId().getContent());
|
||||
String tmp = candidate.replaceAll(" ", "_");
|
||||
try {
|
||||
return URLEncoder.encode(tmp, "UTF-8") + "." + extension;
|
||||
}
|
||||
|
@ -166,17 +166,17 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
}
|
||||
|
||||
protected ProjectAssert downloadZip(String context) {
|
||||
byte[] body = downloadArchive(context);
|
||||
byte[] body = downloadArchive(context).getBody();
|
||||
return zipProjectAssert(body);
|
||||
}
|
||||
|
||||
protected ProjectAssert downloadTgz(String context) {
|
||||
byte[] body = downloadArchive(context);
|
||||
byte[] body = downloadArchive(context).getBody();
|
||||
return tgzProjectAssert(body);
|
||||
}
|
||||
|
||||
protected byte[] downloadArchive(String context) {
|
||||
return this.restTemplate.getForObject(createUrl(context), byte[].class);
|
||||
protected ResponseEntity<byte[]> downloadArchive(String context) {
|
||||
return this.restTemplate.getForEntity(createUrl(context), byte[].class);
|
||||
}
|
||||
|
||||
protected ResponseEntity<String> invokeHome(String userAgentHeader,
|
||||
|
@ -48,8 +48,12 @@ class MainControllerIntegrationTests
|
||||
|
||||
@Test
|
||||
void simpleZipProject() {
|
||||
downloadZip("/starter.zip?style=web&style=jpa").isJavaProject()
|
||||
.hasFile(".gitignore").hasExecutableFile("mvnw").isMavenProject()
|
||||
ResponseEntity<byte[]> entity = downloadArchive(
|
||||
"/starter.zip?style=web&style=jpa");
|
||||
assertArchiveResponseHeaders(entity, MediaType.valueOf("application/zip"),
|
||||
"demo.zip");
|
||||
zipProjectAssert(entity.getBody()).isJavaProject().hasFile(".gitignore")
|
||||
.hasExecutableFile("mvnw").isMavenProject()
|
||||
.hasStaticAndTemplatesResources(true).pomAssert().hasDependenciesCount(3)
|
||||
.hasSpringBootStarterDependency("web")
|
||||
.hasSpringBootStarterDependency("data-jpa") // alias jpa -> data-jpa
|
||||
@ -58,12 +62,24 @@ class MainControllerIntegrationTests
|
||||
|
||||
@Test
|
||||
void simpleTgzProject() {
|
||||
downloadTgz("/starter.tgz?style=org.acme:foo").isJavaProject()
|
||||
.hasFile(".gitignore").hasExecutableFile("mvnw").isMavenProject()
|
||||
ResponseEntity<byte[]> entity = downloadArchive(
|
||||
"/starter.tgz?style=org.acme:foo");
|
||||
assertArchiveResponseHeaders(entity, MediaType.valueOf("application/x-compress"),
|
||||
"demo.tar.gz");
|
||||
tgzProjectAssert(entity.getBody()).isJavaProject().hasFile(".gitignore")
|
||||
.hasExecutableFile("mvnw").isMavenProject()
|
||||
.hasStaticAndTemplatesResources(false).pomAssert().hasDependenciesCount(2)
|
||||
.hasDependency("org.acme", "foo", "1.3.5");
|
||||
}
|
||||
|
||||
private void assertArchiveResponseHeaders(ResponseEntity<byte[]> entity,
|
||||
MediaType contentType, String fileName) {
|
||||
assertThat(entity.getHeaders().getContentType()).isEqualTo(contentType);
|
||||
assertThat(entity.getHeaders().getContentDisposition()).isNotNull();
|
||||
assertThat(entity.getHeaders().getContentDisposition().getFilename())
|
||||
.isEqualTo(fileName);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dependencyInRange() {
|
||||
Dependency biz = Dependency.create("org.acme", "biz", "1.3.5", "runtime");
|
||||
|
Loading…
Reference in New Issue
Block a user