This is an automated email from the ASF dual-hosted git repository. rmaucher pushed a commit to branch 11.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit eee6b09c9692bf8583dea168c23a5e2589031f3c Author: opencode <[email protected]> AuthorDate: Sun Oct 18 20:54:58 2026 +0200 Fix jspc infinite loop with a trailing -trimSpaces argument When -trimSpaces was the final command line argument, nextArg() returned null without consuming a token, the SINGLE value check failed for the null token and the rewind of the argument position to re-process the peeked token moved it back onto the -trimSpaces argument itself. The option was then re-processed forever and jspc never completed. The rewind is now only performed when a token was actually consumed. This also stops the full stop argument from being rewound onto, and later treated as a JSP file name, when -trimSpaces is directly followed by --. Add regression tests for the trailing -trimSpaces argument and for -trimSpaces followed by the full stop argument to TestJspC. --- java/org/apache/jasper/JspC.java | 4 +++- test/org/apache/jasper/TestJspC.java | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/java/org/apache/jasper/JspC.java b/java/org/apache/jasper/JspC.java index 028a3acd71..9071a6f59a 100644 --- a/java/org/apache/jasper/JspC.java +++ b/java/org/apache/jasper/JspC.java @@ -452,7 +452,9 @@ public class JspC extends Task implements Options { xpoweredBy = true; } else if (tok.equals(SWITCH_TRIM_SPACES)) { tok = nextArg(); - if (TrimSpacesOption.SINGLE.toString().equalsIgnoreCase(tok)) { + if (tok == null) { + setTrimSpaces(TrimSpacesOption.TRUE); + } else if (TrimSpacesOption.SINGLE.toString().equalsIgnoreCase(tok)) { setTrimSpaces(TrimSpacesOption.SINGLE); } else { setTrimSpaces(TrimSpacesOption.TRUE); diff --git a/test/org/apache/jasper/TestJspC.java b/test/org/apache/jasper/TestJspC.java index 611cf11b55..1524336d17 100644 --- a/test/org/apache/jasper/TestJspC.java +++ b/test/org/apache/jasper/TestJspC.java @@ -182,6 +182,35 @@ public class TestJspC { Assert.assertEquals(List.of("-compile", "a.jsp"), jspc.pages); } + @Test + public void argsTrimSpacesLast() throws Exception { + // The setArgs() call must return, applying the default value of TRUE. + // Use a thread to avoid the test harness hanging if the option is + // ever re-processed in a loop again. + Thread thread = new Thread(() -> { + try { + jspc.setArgs(new String[] {"-trimSpaces"}); + } catch (JasperException e) { + // Ignore + } + }); + thread.setDaemon(true); + thread.start(); + thread.join(10000); + Assert.assertFalse("setArgs() did not return", thread.isAlive()); + Assert.assertEquals(TrimSpacesOption.TRUE, jspc.getTrimSpaces()); + Assert.assertTrue(jspc.pages.isEmpty()); + } + + @Test + public void argsTrimSpacesBeforeFullStop() throws Exception { + // The full stop argument takes the place of the missing option value + // and must not be added to the list of JSP pages + jspc.setArgs(new String[] {"-trimSpaces", "--", "a.jsp", "b.jsp"}); + Assert.assertEquals(TrimSpacesOption.TRUE, jspc.getTrimSpaces()); + Assert.assertEquals(List.of("a.jsp", "b.jsp"), jspc.pages); + } + @Test public void servletContextUsesAntLog() throws Exception { List<String> messages = new ArrayList<>(); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
