Skip to content

Comments

fix: handle escaped closing brace in template placeholder parsing#813

Open
roeniss wants to merge 3 commits intoapache:mainfrom
roeniss:fix/462
Open

fix: handle escaped closing brace in template placeholder parsing#813
roeniss wants to merge 3 commits intoapache:mainfrom
roeniss:fix/462

Conversation

@roeniss
Copy link

@roeniss roeniss commented Jan 18, 2026

Purpose of the pull request

Closed: #462

What's changed?

Added a bounds check after the inner while loop to break out when no valid (non-escaped) closing brace is found.

Checklist

  • I have read the Contributor Guide.
  • I have written the necessary doc or comment. (in this case, no need I guess)
  • I have added the necessary unit tests and all cases have passed.

When a template placeholder contains an escaped closing brace like {foo\},
the parser would throw StringIndexOutOfBoundsException because it attempted
to use suffixIndex=-1 in a substring operation.

Added a bounds check after the inner while loop to break out when no valid
(non-escaped) closing brace is found.
@roeniss
Copy link
Author

roeniss commented Jan 18, 2026

commit force-pushed due to spotless check

@roeniss
Copy link
Author

roeniss commented Jan 25, 2026

@psxjoy could you review this?

@psxjoy psxjoy self-requested a review January 25, 2026 15:30
@psxjoy psxjoy added the PR: reviewing Currently under active review. label Jan 25, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes template placeholder parsing to avoid an out-of-bounds exception when encountering an escaped closing brace (e.g., {foo\}), addressing issue #462.

Changes:

  • Adds a post-loop bounds check in prepareData to stop parsing when no valid (non-escaped) closing brace is found.
  • Adds a new regression test class covering escaped-brace placeholder scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
fesod-sheet/src/main/java/org/apache/fesod/sheet/write/executor/ExcelWriteFillExecutor.java Prevents parsing from continuing when the suffix scan ends without finding a non-escaped }.
fesod-examples/fesod-sheet-examples/src/test/java/org/apache/fesod/sheet/temp/issue462/EscapedPlaceholderTest.java Introduces tests for escaped closing/opening brace cases and a normal placeholder control case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

private static void createTemplate(String fileName, String content) throws IOException {
File templateFile = new File(TEMPLATE_PATH + fileName);
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createTemplate writes to TEMPLATE_PATH + fileName, but it never ensures that temp/issue462/ exists under the test classpath root. Since src/test/resources/temp/ exists but temp/issue462/ does not, new FileOutputStream(templateFile) will throw FileNotFoundException on a clean checkout. Create the parent directories before opening the stream (or reuse TestFileUtil.createNewFile(...) which already creates parent dirs).

Suggested change
File templateFile = new File(TEMPLATE_PATH + fileName);
File templateFile = new File(TEMPLATE_PATH + fileName);
File parentDir = templateFile.getParentFile();
if (parentDir != null && !parentDir.exists() && !parentDir.mkdirs()) {
throw new IOException("Failed to create directory: " + parentDir);
}

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@psxjoy I think this feedback doesn't make sense, what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: reviewing Currently under active review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] When filling the template, an exception is reported when the placeholder content is '{foo\}'

3 participants