mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 08:24:13 +00:00
DataBufferUtils.TwoByteMatcher inherited AbstractNestedMatcher.match(byte) without providing the mismatch fallback that its siblings implement (KnuthMorrisPrattMatcher backtracks via its suffix-prefix table, and SingleByteMatcher is stateless). As a result, once the first delimiter byte had matched, the match counter stayed at 1 across any number of intervening non-matching bytes, so a later occurrence of the second delimiter byte falsely completed the match. For a two-byte delimiter such as \r\n this made the matcher report a match across non-contiguous bytes. CompositeMatcher prefers the longest delimiter that matches at a position, so the false \r\n match was chosen over a real single \n, causing StringDecoder to strip two bytes and drop the character preceding a lone \n whenever a line contained a stray \r. TwoByteMatcher now overrides match(byte) to reset the counter to 0 when the incoming byte is not the expected next delimiter byte before delegating to super.match(), mirroring KnuthMorrisPrattMatcher. A genuine contiguous delimiter is unaffected. Signed-off-by: junhyeong9812 <pickjog@gmail.com>