Skip to content

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

Draft
roeniss wants to merge 7 commits into
apache:mainfrom
roeniss:fix/462
Draft

roeniss wants to merge 7 commits into
apache:mainfrom
roeniss:fix/462

Conversation

@roeniss

@roeniss roeniss commented Jan 18, 2026

Copy link
Copy Markdown

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

roeniss commented Jan 18, 2026

Copy link
Copy Markdown
Author

commit force-pushed due to spotless check

@roeniss

roeniss commented Jan 25, 2026

Copy link
Copy Markdown
Author

@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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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);

Copilot AI Feb 21, 2026

Copy link

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
Copy Markdown
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?

@psxjoy

psxjoy commented Apr 2, 2026

Copy link
Copy Markdown
Member

@roeniss Hi, can you update the branch and let code in right place ? I think we can merge this PR if everything is already.

@psxjoy psxjoy added the waiting for feedback Waiting for a reply or feedback label Apr 2, 2026
@roeniss
roeniss marked this pull request as draft May 10, 2026 13:23
roeniss and others added 2 commits May 10, 2026 22:25
Per CONTRIBUTING.md, tests should live in the corresponding module's
test directory. The bug under test is in fesod-sheet's
ExcelWriteFillExecutor, so move the test from fesod-examples to
fesod-sheet/src/test/java/.../fill/.

Also use TestFileUtil.createNewFile() for path resolution so parent
directories are created automatically, instead of relying on raw
FileOutputStream which fails on a clean checkout.
@Mikkey-f

Copy link
Copy Markdown
Contributor

Hi @roeniss — checking in on this one. psxjoy mentioned back in April that it would be good to merge once the branch is updated and the code moved into the right place, and the PR has been quiet since July.

Are you still planning to carry it forward? If you don't have the bandwidth for it right now, I'd be happy to pick it up — I'd re-apply the suffixIndex < 0 guard on current main, address psxjoy's placement note with a test that follows the current testkit conventions, and reference this PR and #462 in the description so the original diagnosis stays credited. Either way, just let me know.

@roeniss

roeniss commented Oct 13, 2026

Copy link
Copy Markdown
Author

@Mikkey-f Hi Mikkey, you can carry the issue instead of me. Thanks!

@Mikkey-f

Copy link
Copy Markdown
Contributor

@roeniss Thanks for the go-ahead — carrying it forward as promised.

Re-applied the suffixIndex < 0 guard on current main (your commit is kept,
with you as the author) and rewrote the test against the current testkit
conventions: the TestFileUtil it used was removed in #901, so the test now
extends AbstractExcelTest and builds its templates at runtime. Your four
scenarios are preserved, and the red-side evidence matches the original failure
exactly (StringIndexOutOfBoundsException: begin 1, end -1, length 6).

New PR: #1218 (credits this PR and #462 in its description). Once it is merged,
this one can be closed — thanks again for the diagnosis!

This branch has not been deployed

No deployments
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. waiting for feedback Waiting for a reply or feedback

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\}'

5 participants