Skip to content

Commit

Permalink
Invalid url caused fileName duplication
Browse files Browse the repository at this point in the history
Issue #cucumber-reports-plugin/issues/116
  • Loading branch information
damianszczepanik committed Feb 14, 2017
1 parent 7dee9e9 commit 76f9294
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/main/java/net/masterthought/cucumber/util/Util.java
Expand Up @@ -4,6 +4,7 @@
import java.text.NumberFormat;
import java.util.Locale;

import org.apache.commons.lang3.StringEscapeUtils;
import org.joda.time.Period;
import org.joda.time.format.PeriodFormatter;
import org.joda.time.format.PeriodFormatterBuilder;
Expand Down Expand Up @@ -78,6 +79,6 @@ public static String formatAsDecimal(int value, int total) {
* @return converted string
*/
public static String toValidFileName(String value) {
return value.replaceAll("[^\\d\\w]", "-");
return StringEscapeUtils.escapeJava(value).replaceAll("[^\\d\\w]", "-");
}
}
Expand Up @@ -140,7 +140,7 @@ public void generatePage_generatesStatsTableBody() {
firstRow.hasExactValues("1st feature", "10", "0", "0", "0", "0", "10", "1", "0", "1", "1m 39s 263ms", "Passed");
firstRow.hasExactCSSClasses("tagname", "passed", "", "", "", "", "total", "passed", "", "total", "duration", "passed");
firstRow.hasExactDataValues("", "", "", "", "", "", "", "", "", "", "99263122889", "");
firstRow.getReportLink().hasLabelAndAddress("1st feature", "report-feature_net-masterthought-example-s--ATM-local-feature.html");
firstRow.getReportLink().hasLabelAndAddress("1st feature", "report-feature_net-masterthought-example-s--ATM--u6771-u4EAC-feature.html");

TableRowAssertion secondRow = bodyRows[1];
secondRow.hasExactValues("Second feature", "5", "1", "2", "1", "2", "11", "1", "1", "2", "092ms", "Failed");
Expand All @@ -166,6 +166,5 @@ public void generatePage_generatesStatsTableFooter() {
assertThat(footerRows).hasSize(2);
footerRows[0].hasExactValues("2", "15", "1", "2", "1", "2", "21", "2", "1", "3", "1m 39s 355ms", "");
footerRows[1].hasExactValues("", "71.43%", "4.76%", "9.52%", "4.76%", "9.52%", "", "66.67%", "33.33%", "", "", "50.00%");

}
}
@@ -1,13 +1,15 @@
package net.masterthought.cucumber.util;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

import org.junit.Test;

public class CounterTest {

@Test
public void next_shouldIncrement() {

// given
Counter counter = new Counter();
int initValue = counter.intValue();
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/net/masterthought/cucumber/util/UtilTest.java
@@ -0,0 +1,43 @@
package net.masterthought.cucumber.util;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Arrays;
import java.util.Collection;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

/**
* @author Damian Szczepanik (damianszczepanik@github)
*/
@RunWith(Parameterized.class)
public class UtilTest {

@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{"simpleFile", "simpleFile"},
{"file-dash", "file-dash"},
{"東京", "-u6771-u4EAC"},
{"żółć", "-u017C-u00F3-u0142-u0107"}
});
}

@Parameterized.Parameter(value = 0)
public String value;

@Parameterized.Parameter(value = 1)
public String fileName;

@Test
public void toValidFileName_RemovesInvalidChars() {

// when
String convertedFileName = Util.toValidFileName(value);

// then
assertThat(convertedFileName).isEqualTo(fileName);
}
}
2 changes: 1 addition & 1 deletion src/test/resources/json/sample.json
Expand Up @@ -268,7 +268,7 @@
]
}
],
"uri": "net/masterthought/example(s)/ATM:local.feature"
"uri": "net/masterthought/example(s)/ATM:東京.feature"
},
{
"id": "account-holder-withdraws-more-cash",
Expand Down

0 comments on commit 76f9294

Please sign in to comment.