Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling Unicode in Project Generation #1345

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.spring.initializr.web.project;

import java.text.Normalizer;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand All @@ -34,6 +35,7 @@
import io.spring.initializr.metadata.support.MetadataBuildItemMapper;

import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

/**
* A default {@link ProjectRequestToDescriptionConverter} implementation that uses the
Expand All @@ -44,6 +46,7 @@
* @author Madhura Bhave
* @author HaiTao Zhang
* @author Stephane Nicoll
* @author Nirbhay Mishra
*/
public class DefaultProjectRequestToDescriptionConverter
implements ProjectRequestToDescriptionConverter<ProjectRequest> {
Expand Down Expand Up @@ -82,14 +85,14 @@ public void convert(ProjectRequest request, MutableProjectDescription descriptio
validateDependencyRange(platformVersion, resolvedDependencies);

description.setApplicationName(request.getApplicationName());
description.setArtifactId(request.getArtifactId());
description.setArtifactId(cleanInputValue(request.getArtifactId()));
description.setBaseDirectory(request.getBaseDir());
description.setBuildSystem(getBuildSystem(request, metadata));
description.setDescription(request.getDescription());
description.setGroupId(request.getGroupId());
description.setGroupId(cleanInputValue(request.getGroupId()));
description.setLanguage(Language.forId(request.getLanguage(), request.getJavaVersion()));
description.setName(request.getName());
description.setPackageName(request.getPackageName());
description.setName(cleanInputValue(request.getName()));
description.setPackageName(cleanInputValue(request.getPackageName()));
description.setPackaging(Packaging.forId(request.getPackaging()));
description.setPlatformVersion(platformVersion);
description.setVersion(request.getVersion());
Expand Down Expand Up @@ -188,4 +191,11 @@ private List<Dependency> getResolvedDependencies(ProjectRequest request, Version
}).collect(Collectors.toList());
}

private String cleanInputValue(String inputString) {
if (StringUtils.hasText(inputString)) {
return Normalizer.normalize(inputString, Normalizer.Form.NFKD).replaceAll("\\p{M}", "");
}
return inputString;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ void baseDirectorySeparatedBySpace() {
assertDefaultProject(project.resolveModule("demo trial"));
}

@Test
void projectNameWithAccentRemoved() {
ProjectStructure project = downloadZip("/starter.zip?artifactId=demo&baseDir=demo trial&name=Demö");
assertDefaultProject(project.resolveModule("demo trial"));
}

}