Fix setEscapeString(null) to clear escape state - #373
Conversation
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
left a comment
There was a problem hiding this comment.
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
|
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 Please assign appropriate label to PR according to the type of change. |
|
@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 |
Problem
setEscapeString(null)andsetEscapeString("")were silently ignored inAbstractFilterReaderLineEnding. When called after a previous non-null value, the old escape string anduseEscapeflag were retained, so escaping remained active.Fix
Changed
setEscapeStringto explicitly clearescapeStringtonullanduseEscapetofalsewhen the input is null or empty, and movedcalculateMarkLength()outside the conditional so it's always called.Tests
Added two tests that verify both
nulland empty string properly disable escaping:setEscapeStringNullShouldDisableEscaping-- sets escape to\\, thennull, assertsgetEscapeString()returns nullsetEscapeStringEmptyShouldDisableEscaping-- sets escape to\\, then"", assertsgetEscapeString()returns nullBoth tests fail before the fix (
expected: <null> but was: <\>) and pass after. All 75 tests pass.Closes #351