Skip to content
Merged
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 @@
import java.util.concurrent.Executors;

import static org.jsmart.zerocode.core.constants.ZeroCodeReportConstants.TARGET_REPORT_DIR;
import static org.jsmart.zerocode.core.utils.SmartUtils.sanitizeReportFileName;
import static org.slf4j.LoggerFactory.getLogger;

public class ZeroCodeIoWriteBuilder {
Expand Down Expand Up @@ -60,6 +61,7 @@ public synchronized void printToFile(String fileName) {

final ObjectMapper mapper = new ObjectMapperProvider().get();

fileName = sanitizeReportFileName(fileName);
File file = new File(TARGET_REPORT_DIR + fileName);
file.getParentFile().mkdirs();
mapper.writeValue(file, this.built);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public Map<String, Object> readJsonStringAsMap(String json) throws IOException {
return map;
}

public static String sanitizeReportFileName(String fileName) {
return fileName.replaceAll("[^A-Za-z0-9 \\-_.]", "_");
}

public static List<String> getAllEndPointFiles(String packageName) {
if(isValidAbsolutePath(packageName)){
return retrieveScenariosByAbsPath(packageName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -236,6 +237,13 @@ public void testSuiteFolder_symAbsolutePath() {
assertThat(allScenarios.get(0), containsString("cherry_pick_tests/folder_b/test_case_2.json"));
}

@Test
public void testSanitizeReportFile() {
String orig = "file !#$%&'()*+,-./09:;<=>?@AZ[]^_`az{|}~\"\\";
String dest = "file ___________-._09_______AZ_____az______";
assertThat(SmartUtils.sanitizeReportFileName(orig), equalTo(dest));
}

// Move this to File Util class
private static File createCascadeIfNotExisting(String fileName) {
try {
Expand Down