fix: escape string values for date/date-time/time formats - #860
Merged
Conversation
`asDateTime`, `asDate` and `asTime` concatenated string inputs straight between quotes, so a value containing `"`, `\`, a control character or a lone surrogate produced a document that is not valid JSON. Plain `type: string` fields already went through `asString`, so the behavior was inconsistent depending on `format`. Route the string branch of the three functions through the existing escaping routine, which is hoisted to module scope since the generated code destructures the serializer methods and calls them unbound. `Date` inputs keep the plain concatenation: `toISOString()` never needs escaping. Serializing a date-format string is now as expensive as serializing a regular string of the same length; `Date` values are unaffected. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TmhA1oTx5qUWc6UmEgWuar
Member
Author
|
The real reason for this is so we stop receiving reports. |
Fdawgs
approved these changes
Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
asDateTime,asDateandasTimeconcatenate string inputs straight between quotes:So a string value containing
",\, a control character or a lone surrogate produces output that is not valid JSON:Plain
type: stringfields already go throughasString, so whether a string got escaped depended onformat, which is surprising.Fix
asString(str); the class method delegates to it. This is needed because the generated code destructures the serializer methods and calls them unbound, sothis.asStringisn't reachable fromasDateTime& co.asDateTime/asDate/asTimethrough it.Dateinputs keep the plain concatenation —toISOString()output can never need escaping.format: 'unsafe'is untouched; it remains the documented way to opt out of escaping.Notes
Datevalues are unaffected.Test
New case in
test/date.test.jsasserts all three formats round-trip quotes, backslashes, control characters and lone surrogates identically toJSON.stringify.🤖 Generated with Claude Code
https://claude.ai/code/session_01TmhA1oTx5qUWc6UmEgWuar