Skip to content

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

Merged
elharo merged 1 commit into
masterfrom
fix/setEscapeString-null-handling
Aug 20, 2026
Merged

Fix setEscapeString(null) to clear escape state#373
elharo merged 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

@rmannibucau rmannibucau left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

OK for me but wondered why setEscapeString(null) doesn't just throw so can be worth a comment

PS: just realizing than the "plan" (TODO) was to throw on null so really worth an explanation why the "common expected" behavior and original intent are no more valid

@elharo

elharo commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

I think no NullPointerException here does make sense since most artifacts don't have classifiers most of the time so we need a way to say "no classifier". And even of we threw for null, we still don't want the extra dash for the empty string.

@elharo
elharo merged commit d39618d into master Aug 20, 2026
13 checks passed
@elharo
elharo deleted the fix/setEscapeString-null-handling branch August 20, 2026 20:45
@github-actions

Copy link
Copy Markdown

@elharo Please assign appropriate label to PR according to the type of change.

@github-actions github-actions Bot added this to the 4.0.0-beta-2 milestone Aug 20, 2026
@elharo elharo added the bug Something isn't working label Aug 20, 2026
@rmannibucau

Copy link
Copy Markdown

@elharo this is not strictly related to classifier, did you mixed some other PR or did I miss some context? also can be sane to test the read() method of the interpolator since it will read the first char of the escapestring so covering it is handled is not crazy. Now back to null: empty is enough to disable escaping handling IMHO

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

setEscapeString(null) silently ignored, previous state retained

2 participants