Skip to content

Fix setEscapeString(null) to clear escape state - #373

Open
elharo wants to merge 1 commit into
masterfrom
fix/setEscapeString-null-handling
Open

Fix setEscapeString(null) to clear escape state#373
elharo wants to merge 1 commit into
masterfrom
fix/setEscapeString-null-handling

Conversation

@elharo

@elharo elharo commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Problem

setEscapeString(null) and setEscapeString("") were silently ignored in AbstractFilterReaderLineEnding. When called after a previous non-null value, the old escape string and useEscape flag were retained, so escaping remained active.

Fix

Changed setEscapeString to explicitly clear escapeString to null and useEscape to false when the input is null or empty, and moved calculateMarkLength() outside the conditional so it's always called.

Tests

Added two tests that verify both null and empty string properly disable escaping:

  • setEscapeStringNullShouldDisableEscaping -- sets escape to \\, then null, asserts getEscapeString() returns null
  • setEscapeStringEmptyShouldDisableEscaping -- sets escape to \\, then "", asserts getEscapeString() returns null

Both tests fail before the fix (expected: <null> but was: <\>) and pass after. All 75 tests pass.

Closes #351

setEscapeString(null) and setEscapeString("") were silently ignored,
leaving the previous escape string and useEscape flag intact. A caller
who sets escape string to non-null, then later sets it to null to
disable escaping, would find escaping still active with the old string.

Fix by clearing escapeString to null and useEscape to false when the
input is null or empty, and always call calculateMarkLength().

Also added tests verifying both null and empty string disable escaping.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

setEscapeString(null) silently ignored, previous state retained

1 participant