Repository navigation
Conversation
There was a problem hiding this comment.
Thanks for the fix @Mikkey-f. I found one remaining edge case: with {foo} {bar}, the scan consumes {bar}'s closing brace as part of the first placeholder, causing the output row to disappear. Could you update the parser to resume at the next placeholder and add this regression case?
| @Test | ||
| void escapedPlaceholderInsideTextIsKeptAsLiteralText() throws IOException { | ||
| Assertions.assertEquals("prefix {foo\\} suffix", fillTemplateWith("prefix {foo\\} suffix")); | ||
| } |
There was a problem hiding this comment.
Please add the mixed case that exposes the remaining parser error.
| } | |
| } | |
| @Test | |
| void escapedPlaceholderBeforeNormalPlaceholderIsHandledIndependently() throws IOException { | |
| Assertions.assertEquals("{foo\\} second_value", fillTemplateWith("{foo\\} {bar}")); | |
| } |
| File template = createTemplate(cellText); | ||
| File output = createTempFile("escaped-placeholder-out", ExcelFormat.XLSX); | ||
| Map<String, Object> data = new HashMap<>(); | ||
| data.put(VARIABLE, VALUE); |
There was a problem hiding this comment.
This supplies the normal placeholder used by the regression case.
| data.put(VARIABLE, VALUE); | |
| data.put(VARIABLE, VALUE); | |
| data.put("bar", "second_value"); |
|
Thanks @skytin1004 — fixed in bbe472d. The parser now treats an opener whose closing brace is escaped as literal text Verification: EscapedPlaceholderTest 5/5; full suite 1150 (60 + 1090) with 0 |
Purpose of the pull request
Fixes #462. Supersedes #813 by @roeniss — the diagnosis, the fix and the original test scenarios are his; I re-applied the change on current main and rewrote the test to follow the post-#901 testkit conventions.
Filling a template whose placeholder has an escaped closing brace (a cell
containing
{foo\}) aborts withStringIndexOutOfBoundsException:The inner loop that looks for a valid (non-escaped) closing brace can exit
because
startIndexran past the end of the value, leavingsuffixIndex == -1;only the other exit path (
indexOfreturning-1) was handled, sovalue.substring(prefixIndex + 1, -1)blows up. A placeholder with an escapedclosing brace has no valid closing brace to parse and should be kept as-is.
A related edge case remains when a normal placeholder follows: in
{foo\} {bar}the scan used to consume{bar}'s closing brace, parsefoo\} {baras the variable name and drop the row. An escaped closing bracemust only end the literal placeholder, so parsing now resumes at the next
{.What's changed?
ExcelWriteFillExecutor.prepareData: an escaped closing brace no longerends or derails the placeholder scan. When another
{starts before thenext non-escaped
}, the opener is kept as literal text and parsingresumes at that next placeholder, so
{foo\} {bar}fills to{foo\} second_value. The closing-brace scan now also starts after thecurrent opener instead of possibly scanning past it.
EscapedPlaceholderTest(5 cases): a one-cell template is filled withfoo=replaced_valueand the cell is read back —{foo\}(escaped closing brace) → cell stays{foo\}prefix {foo\} suffix→ cell stays as-is\{foo}(escaped opening brace) → cell stays as-is{foo}→ still replaced withreplaced_value{foo\} {bar}→{foo\} second_value(the escaped placeholder is kept,the following placeholder is still filled)
Verification
(the fill drops the row); before the earlier guard,
{foo\}threwStringIndexOutOfBoundsException: begin 1, end -1, length 6.EscapedPlaceholderTest.mvn clean package -Dmaven.test.skip=false -pl fesod-common,fesod-shaded,fesod-sheet→ 60 + 1090 tests, 0 failures.spotless:checkandjavadoc:javadocpass.bbe472d4.Notes
behind and its test depends on
TestFileUtil, removed in [Test] Add testkit infrastructure and refactor unit tests with JUnit 5 parameterized patterns #901.Checklist