This is an automated email from the ASF dual-hosted git repository. rmaucher pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 6fdde8313c90366ee47db6c1924eff264c053337 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 | 30 +++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/java/org/apache/jasper/JspC.java b/java/org/apache/jasper/JspC.java index 6b22c771f7..9ce0fd2f4f 100644 --- a/java/org/apache/jasper/JspC.java +++ b/java/org/apache/jasper/JspC.java @@ -456,7 +456,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 ebcc7e9051..50df5f928f 100644 --- a/test/org/apache/jasper/TestJspC.java +++ b/test/org/apache/jasper/TestJspC.java @@ -151,7 +151,35 @@ public class TestJspC { } @Test ->>>>>>> 79e8d06f4c (Fix jspc handling of the full stop (--) argument) + 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<>(); Project project = new Project(); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
