Skip to content

Use post-serialization RFC 8259 Unicode escaping for JSON-LD output - #64

Merged
Eyas merged 3 commits into
google:mainfrom
Eyas:rfc8259-escaping
Nov 28, 2026
Merged

Eyas merged 3 commits into
google:mainfrom
Eyas:rfc8259-escaping

Conversation

@Eyas

@Eyas Eyas commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Switch from HTML-entity escaping inside the JSON.stringify replacer to post-serialization RFC 8259 Unicode escaping (\u003c, \u003e, \u0026, \u2028, \u2029, \ufffe, \uffff, and unpaired UTF-16 surrogates while preserving valid surrogate pairs). This applies escaping consistently across the full serialized JSON output (both property names and values) and preserves lossless JSON.parse() round-tripping per RFC 8259.
  • Retain omitNullReplacer for omitting null object properties and normalize options.space from own properties to finite numbers (0..10) or strict RFC 8259 whitespace (/^[ \t\r\n]*$/).
  • Replace deprecated react-test-renderer with react-dom/server (renderToStaticMarkup) in test/jsonld_component_test.tsx, with corresponding tsconfig updates so src/ and type-test/ remain DOM-free.
  • Bump package version to 2.0.2.

Eyas added 3 commits November 28, 2026 15:21
Move character escaping out of the JSON.stringify replacer and onto the
serialized JSON string using standard RFC 8259 Unicode escape sequences
(`\u003c`, `\u003e`, `\u0026`, `\u2028`, `\u2029`, `\ufffe`, `\uffff`,
and unpaired UTF-16 surrogates while preserving valid surrogate pairs).

This ensures consistent escaping across all serialized JSON output
(including property names and values), preserves lossless JSON.parse()
round-tripping without HTML-entity encoding in string values, keeps
null property omission via omitNullReplacer, and normalizes
options.space to valid RFC 8259 indentation whitespace or finite
numbers.
Swap react-test-renderer and @types/react-test-renderer for react-dom
and @types/react-dom in devDependencies, and render <JsonLd> in
test/jsonld_component_test.tsx using renderToStaticMarkup. This removes
the React 19 deprecation warnings and act()/IS_REACT_ACT_ENVIRONMENT
boilerplate while directly verifying serialized <script> output.

Add DOM to test/tsconfig.json lib, set `"types": []` in
src/tsconfig.json and type-test/tsconfig.json, and mark the root
tsconfig.json with `"files": []` so @types/react-dom type-checks cleanly
in tests without adding DOM types to src/ or type-test/.
@Eyas
Eyas merged commit 604ec94 into google:main Nov 28, 2026
10 checks passed
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.

1 participant