This is an automated email from the ASF dual-hosted git repository. mraible pushed a commit to branch filter-order-test-skips-comments-6.1.x in repository https://gitbox.apache.org/repos/asf/roller.git
commit 7d1ac185945b1c107f2461205b3780724ed5452c Author: Matt Raible <[email protected]> AuthorDate: Tue Nov 17 20:07:22 2026 -0700 Ignore commented-out filter mappings in FilterOrderTest The test read filter mappings straight from web.xml, so a commented-out mapping would have counted. It now strips XML comments first, and a new test checks that a commented-out mapping is ignored. --- .../weblogger/ui/core/filters/FilterOrderTest.java | 32 ++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/core/filters/FilterOrderTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/core/filters/FilterOrderTest.java index 2b7fc047e..8fb08b5ec 100644 --- a/app/src/test/java/org/apache/roller/weblogger/ui/core/filters/FilterOrderTest.java +++ b/app/src/test/java/org/apache/roller/weblogger/ui/core/filters/FilterOrderTest.java @@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -35,15 +36,36 @@ class FilterOrderTest { void persistenceSessionFilterWrapsEveryOtherFilter() throws Exception { String webXml = new String(Files.readAllBytes(Paths.get("src/main/webapp/WEB-INF/web.xml")), StandardCharsets.UTF_8); + List<String> order = filterMappingOrder(webXml); + // Spring Security reads users for logins and answers those requests + // itself, so the filter that releases the persistence session has to + // run around it + assertEquals("PersistenceSessionFilter", order.get(0), order.toString()); + } + + @Test + void commentedOutMappingsAreIgnored() { + String webXml = "<web-app>\n" + + " <!-- <filter-mapping>\n" + + " <filter-name>OldFilter</filter-name>\n" + + " </filter-mapping> -->\n" + + " <filter-mapping>\n" + + " <filter-name>FirstFilter</filter-name>\n" + + " </filter-mapping>\n" + + "</web-app>\n"; + assertEquals(Collections.singletonList("FirstFilter"), filterMappingOrder(webXml)); + } + + // the filter names of web.xml's filter mappings, in order, leaving out + // any that are commented out + private static List<String> filterMappingOrder(String webXml) { + String uncommented = webXml.replaceAll("(?s)<!--.*?-->", ""); Matcher mapping = Pattern.compile("<filter-mapping>\\s*<filter-name>([^<]+)</filter-name>") - .matcher(webXml); + .matcher(uncommented); List<String> order = new ArrayList<>(); while (mapping.find()) { order.add(mapping.group(1).trim()); } - // Spring Security reads users for logins and answers those requests - // itself, so the filter that releases the persistence session has to - // run around it - assertEquals("PersistenceSessionFilter", order.get(0), order.toString()); + return order; } }
