Repository navigation
fix: a declaration's strings are written by one fixed rule, so its key is the same on every runtime - #53
Merged
Conversation
…y is the same on every runtime Closes #49. The identity an unnamed declaration's key is hashed over, and the stored value, went through JavaScriptEncoder.UnsafeRelaxedJsonEscaping, which escapes every code point its runtime does not know as assigned. .NET 9 escaped 22 characters that .NET 10 writes as themselves, so one declaration had two keys. CanonicalJson now writes every string: `"`, `\` and what is below U+0020 are escaped, and so are U+0085, U+2028 and U+2029. Everything else is written as itself. The last three are not JSON's: EF Core writes the value into a string literal in the snapshot without escaping them, and they end a line in C#, so the snapshot did not compile. The round trip through a compiled snapshot found that. Also: - a string that is not well-formed UTF-16 is refused instead of being stored as U+FFFD - a property name is ASCII letters, digits and `_`, since a name still goes through the writer's encoder Keys of declarations made of ASCII do not move; the two golden keys hold. Co-Authored-By: Claude Fable 5.2 <[email protected]>
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.
Closes #49
Problem
The identity an unnamed declaration's key is hashed over, and the stored value, were written through
JavaScriptEncoder.UnsafeRelaxedJsonEscaping. That encoder escapes every code point its runtime does not know as assigned, and each Unicode version assigns more: .NET 9 escaped 22 BMP characters that .NET 10 writes as themselves. One declaration therefore had two keys, depending on the runtime that scaffolded. The key sits in consumers' snapshots and is permanent from 11.0.0.A consumer would have seen, after a runtime major: the snapshot rewritten for declarations nobody changed, another order from
GetDeclarations, and achangedcount fromRedeclare.Change
Declarations/Internal/CanonicalJson.cs(new) writes every string of a stored declaration by one rule that reads no table:",\and everything below U+0020 are escaped (\b \t \n \f \r, otherwise\uand four upper-case hex digits), and so are U+0085, U+2028 and U+2029. Everything else is written as itself.SchemaJsonWriter(String,OptionalString,Strings) andDeclarationCodec(the kind and the name) write through it._.Utf8JsonWriterhas no raw form for a name, so names still go through its encoder; these are the characters no encoder escapes. This narrows the experimental contract; every name in the repository complies.CLAUDE.mdhas the rule.Why three characters more than JSON asks for. With U+2028 written as itself, the snapshot EF Core scaffolds does not compile (
CS1010, newline in constant): EF Core writes an annotation's value into a C# string literal and does not escape U+0085, U+2028 or U+2029, which end a line in C#. The old encoder happened to escape them.SnapshotRoundTripTestsfound it once its declaration had such a character.Keys of declarations made of ASCII do not move. Both golden keys in
DeclarationStoreTestsare unchanged.Tests
Kernel tests without a server: 252 before, 263 after. Probe project: 125, unchanged. The two PostgreSQL integration tests did not run locally (
SCHEMAKIT_TEST_PGnot set); CI runs them.CanonicalJson.cswrote every BMP character and one outside it on .NET 9.0.23, 10.0.15 and 11.0.0: the bytes are identical (SHA-256a1669ffa0cbcaadc…on all three) and read back as the string that was written.shasum.Each part was undone in turn and the tests run:
Stringthrough the runtime's encoderEvery_character_is_written_as_itself_…,A_key_does_not_depend_on_what_the_runtime_knows_of_a_character,A_string_that_is_not_well_formed_is_refusedOptionalString;Strings; the nameEvery_character_is_written_as_itself_…,A_string_that_is_not_well_formed_is_refused(each)Every_character_is_written_as_itself_…A_string_is_escaped_where_json_requires_it_and_nowhere_else, and the snapshot round trip on all three providers, which no longer compilesA_string_that_is_not_well_formed_is_refusedA_property_name_is_made_of_ascii_letters_digits_and_underscores(6 rows)🤖 Generated with Claude Code