Skip to content

Commit

Permalink
Bump com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitiz…
Browse files Browse the repository at this point in the history
…er from 20220608.1 to 20240325.1

- removes guava dependency
- deletes tests that examines sanitizer library
- update other test to be working with different JDK versions
  • Loading branch information
damianszczepanik committed Jul 7, 2024
1 parent ad9eba0 commit 5937c3d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 44 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
<dependency>
<groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
<artifactId>owasp-java-html-sanitizer</artifactId>
<version>20220608.1</version>
<version>20240325.1</version>
</dependency>

<dependency>
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/net/masterthought/cucumber/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import net.masterthought.cucumber.reducers.ReducingMethod;
import net.masterthought.cucumber.sorting.SortingMethod;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.nullness.qual.NonNull;

public class Configuration {

Expand Down Expand Up @@ -331,7 +330,7 @@ public void setNotFailingStatuses(Set<Status> notFailingStatuses) {
* @param jsonFileName JSON file name - without the extension
* @param qualifier Qualifier to use
*/
public void setQualifier(@NonNull String jsonFileName, @NonNull String qualifier) {
public void setQualifier(String jsonFileName, String qualifier) {
qualifiers.put(jsonFileName, qualifier);
}

Expand All @@ -341,7 +340,7 @@ public void setQualifier(@NonNull String jsonFileName, @NonNull String qualifier
* @param jsonFileName JSON file name - without the extension
* @return Qualifier specified for this file or <code>null</code> if none specified
*/
public String getQualifier(@NonNull String jsonFileName) {
public String getQualifier(String jsonFileName) {
return qualifiers.get(jsonFileName);
}

Expand All @@ -351,7 +350,7 @@ public String getQualifier(@NonNull String jsonFileName) {
* @param jsonFileName JSON file name - without the extension
* @return <code>true</code> if the qualifier was specified, <code>false</code> otherwise
*/
public boolean containsQualifier(@NonNull String jsonFileName) {
public boolean containsQualifier(String jsonFileName) {
return qualifiers.containsKey(jsonFileName);
}

Expand All @@ -360,7 +359,7 @@ public boolean containsQualifier(@NonNull String jsonFileName) {
*
* @param jsonFileName JSON file name - without the extension
*/
public void removeQualifier(@NonNull String jsonFileName) {
public void removeQualifier(String jsonFileName) {
qualifiers.remove(jsonFileName);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package net.masterthought.cucumber.reducers;

import net.masterthought.cucumber.json.Element;
import net.masterthought.cucumber.json.Feature;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.google.common.base.Preconditions.checkArgument;
import net.masterthought.cucumber.json.Element;
import net.masterthought.cucumber.json.Feature;

/**
* Merge list of given features. If there are couple of scenarios with the same Id then
* only the latest will be stored into the report.
*
* <p>
* Uses when need to generate a report with rerun results of failed tests.
*/
final class ReportFeatureWithRetestMerger implements ReportFeatureMerger {

private static final String ERROR = "You are not able to use this type of results merge. The start_timestamp field" +
" should be part of element object. Please, update the cucumber-jvm version.";

private static final ElementComparator ELEMENT_COMPARATOR = new ElementComparator();

@Override
Expand All @@ -29,8 +28,7 @@ public List<Feature> merge(List<Feature> features) {
Feature mergedFeature = mergedFeatures.get(candidate.getId());
if (mergedFeature == null) {
mergedFeatures.put(candidate.getId(), candidate);
}
else {
} else {
updateElements(mergedFeatures.get(candidate.getId()), candidate.getElements());
}
}
Expand All @@ -44,24 +42,25 @@ public List<Feature> merge(List<Feature> features) {
*
* @param feature - target object of Feature class.
* @param elements - list of elements which need to be inserted to the @feature with replacing
* or adding to the end.
* or adding to the end.
*/
void updateElements(Feature feature, Element[] elements) {
for (int i = 0; i < elements.length; i++) {
Element current = elements[i];
if (current.isScenario()) {
checkArgument(current.getStartTime() != null, ERROR);
if (current.getStartTime() == null) {
throw new IllegalArgumentException(ERROR);
}
int indexOfPreviousResult = find(feature.getElements(), current);
boolean hasBackground = isBackground(i - 1, elements);

if (indexOfPreviousResult < 0) {
feature.addElements(
hasBackground ?
new Element[] {elements[i - 1], current} :
new Element[] {current}
);
}
else {
new Element[]{elements[i - 1], current} :
new Element[]{current}
);
} else {
if (replaceIfExists(feature.getElements()[indexOfPreviousResult], current)) {
feature.getElements()[indexOfPreviousResult] = current;
if (hasBackground && isBackground(indexOfPreviousResult - 1, feature.getElements())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import net.masterthought.cucumber.json.Feature;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.commons.io.filefilter.WildcardFileFilter.Builder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.powermock.reflect.Whitebox;
Expand Down Expand Up @@ -222,8 +221,8 @@ void copyCustomResources_OnDirAsFile_ThrowsIOException() throws Exception {
File dir = new File("src/test/resources/js");

// when & then
assertThatThrownBy(() -> Whitebox.invokeMethod(builder, "copyCustomResources", "js", dir))
.isInstanceOf(ValidationException.class);
assertThatThrownBy(() -> Whitebox.invokeMethod(builder, "copyCustomResources", "js", dir))
.isInstanceOf(ValidationException.class);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package net.masterthought.cucumber.generators;

import org.apache.velocity.app.event.ReferenceInsertionEventHandler;
import org.junit.jupiter.api.Test;

import static org.apache.commons.text.StringEscapeUtils.escapeHtml4;
import static org.assertj.core.api.Assertions.assertThat;

import org.apache.velocity.app.event.ReferenceInsertionEventHandler;
import org.junit.jupiter.api.Test;

/**
* @author M.P. Korstanje (mpkorstanje@github)
*/
Expand All @@ -15,7 +15,7 @@ class EscapeHtmlReferenceTest {
private final ReferenceInsertionEventHandler insertionEventHandler = new EscapeHtmlReference();

@Test
void referenceInsert_returnNormalText(){
void referenceInsert_returnNormalText() {
// given
String normalText = "a plain statement";

Expand All @@ -27,7 +27,7 @@ void referenceInsert_returnNormalText(){
}

@Test
void referenceInsert_shouldEscapeHtmlForAnyLabel(){
void referenceInsert_shouldEscapeHtmlForAnyLabel() {
// given
String html = "<b>a bold statement</b>";

Expand All @@ -39,7 +39,7 @@ void referenceInsert_shouldEscapeHtmlForAnyLabel(){
}

@Test
void referenceInsert_shouldNotEscapeWithSpecialTag(){
void referenceInsert_shouldNotEscapeWithSpecialTag() {
// given
String html = "<b>a bold statement</b>";

Expand All @@ -51,7 +51,7 @@ void referenceInsert_shouldNotEscapeWithSpecialTag(){
}

@Test
void referenceInsert_shouldReturnNullForNull(){
void referenceInsert_shouldReturnNullForNull() {
// given
String html = null;

Expand All @@ -61,16 +61,4 @@ void referenceInsert_shouldReturnNullForNull(){
// then
assertThat(result).isNull();
}

@Test
void referenceInsert_shouldSanitize(){
// given
String html = "<a href=\"www.example.com\" rel=\"nofollow noopener noreferrer\">a hyper web reference</a>";

// when
Object result = insertionEventHandler.referenceInsert(null, "$_sanitize_" + SOME_REFERENCE, html);

// result
assertThat(result).isEqualTo(html);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ void generatePage_generatesLead() {
void generatePage_generatesClassifications() {

// given
final String[] names = {"Platform", "Browser", "Branch", "Repository"};
final String[] values = {"Win", "Opera", "master", "<a href=\"example.com\" rel=\"nofollow noopener noreferrer\">Example Repository</a>"};
// do not validate url as this is sanitized differently between JDKs 11, 17, 21
final String[] names = {"Platform", "Browser", "Branch"};
final String[] values = {"Win", "Opera", "master"};
setUpWithJson(SAMPLE_JSON);
for (int i = 0; i < names.length; i++) {
configuration.addClassifications(names[i], values[i]);
Expand Down

0 comments on commit 5937c3d

Please sign in to comment.