Skip to content

Fix byUnicodePattern dropping an escaped quote inside a literal - #649

Merged
dkhalanskyjb merged 2 commits into
Kotlin:masterfrom
lenamonj:fix-unicode-pattern-escaped-quote
Sep 7, 2026
Merged

dkhalanskyjb merged 2 commits into
Kotlin:masterfrom
lenamonj:fix-unicode-pattern-escaped-quote

Conversation

@lenamonj

@lenamonj lenamonj commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

byUnicodePattern drops the escaped quote inside a quoted literal. The Unicode pattern grammar spells an apostrophe inside a literal as '', and java.time formats 'o''clock' as o'clock; here it formats as oclock and only parses that spelling. The parser walked the pattern by character, so on a ' inside a literal it could not see whether the next character was another '.

This walks the pattern by index and treats '' inside a literal as one apostrophe; a lone ' still closes the literal. Adds a test over six pattern shapes.

Found by an automated audit; the fix and the test were reviewed and verified by a person on a fresh clone with jvmTest, jsTest and wasmJsTest.

@dkhalanskyjb dkhalanskyjb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The fix looks correct, but the tests can be improved.

assertEquals(time, format.parse(expected), pattern)
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The test location isn't right. At the very least, it's not DateTimeFormatTest, as there are no dates involved. In my opinion, the best place to put this is UnicodeFormatTest. It's JVM-only, which reduces the coverage, but in exchange, we can write tests confirming that Java does exhibit the same behavior as our implementation.

@lenamonj

lenamonj commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Moved it to UnicodeFormatTest as a checkPattern case list, so each pattern is formatted and parsed by both this implementation and java.time and the strings compared. Removed from DateTimeFormatTest. jvmTest and apiCheck green on a fresh clone; the o''clock case fails on master without the fix.

@dkhalanskyjb
dkhalanskyjb merged commit 88ad894 into Kotlin:master Sep 7, 2026
@lenamonj
lenamonj deleted the fix-unicode-pattern-escaped-quote branch September 7, 2026 12:38
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.

2 participants