mirror of
https://github.com/Athou/commafeed.git
synced 2026-11-06 04:16:54 +00:00
fix quadratic time when removing doctype declarations
This commit is contained in:
@@ -4,6 +4,8 @@ import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
class XMLCleanerTest {
|
||||
|
||||
XMLCleaner xmlCleaner = new XMLCleaner();
|
||||
@@ -279,5 +281,39 @@ class XMLCleanerTest {
|
||||
String source = "<!DOCTYPE html ><html></html>";
|
||||
Assertions.assertEquals("<html></html>", xmlCleaner.removeDoctypeDeclarations(source));
|
||||
}
|
||||
|
||||
@Test
|
||||
void preservesUnterminatedDoctype() {
|
||||
String source = "<html></html><!DOCTYPE html";
|
||||
Assertions.assertEquals(source, xmlCleaner.removeDoctypeDeclarations(source));
|
||||
}
|
||||
|
||||
@Test
|
||||
void removesTerminatedDoctypeAndPreservesUnterminatedDoctype() {
|
||||
String source = "<!DOCTYPE html><html></html><!DOCTYPE html";
|
||||
Assertions.assertEquals("<html></html><!DOCTYPE html", xmlCleaner.removeDoctypeDeclarations(source));
|
||||
}
|
||||
|
||||
@Test
|
||||
void removesNestedDoctypeUpToFirstClosingBracket() {
|
||||
String source = "<!DOCTYPE<!DOCTYPE html><html></html>";
|
||||
Assertions.assertEquals("<html></html>", xmlCleaner.removeDoctypeDeclarations(source));
|
||||
}
|
||||
|
||||
@Test
|
||||
void handlesManyUnterminatedDoctypesInLinearTime() {
|
||||
String source = "<!DOCTYPE".repeat(64000);
|
||||
Assertions.assertTimeout(
|
||||
Duration.ofSeconds(2),
|
||||
() -> Assertions.assertEquals(source, xmlCleaner.removeDoctypeDeclarations(source)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void handlesManyUnterminatedDoctypesAfterClosingBracketInLinearTime() {
|
||||
String source = "<a>" + "<!DOCTYPE".repeat(64000);
|
||||
Assertions.assertTimeout(
|
||||
Duration.ofSeconds(2),
|
||||
() -> Assertions.assertEquals(source, xmlCleaner.removeDoctypeDeclarations(source)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user