fix: strip Sanity Stega zero-width characters from SEO meta tags - #44
Merged
Conversation
Sanity's Stega encoding injects invisible zero-width Unicode characters into text fields for visual editing overlays. These were leaking into og:title, og:description, twitter:title, twitter:description, and the standard meta description — causing garbled social sharing previews. Added stripStega() helper that removes characters in the Stega Unicode ranges (U+200B-U+200F, U+2028-U+202F, U+2060-U+2063, U+FEFF, U+FFF9-U+FFFB) before values are used in meta tags.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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
Sanity's Stega encoding injects invisible zero-width Unicode characters into text fields for visual editing overlays. These were leaking into all SEO meta tags — , , , , and the standard \ — causing garbled or polluted social sharing previews.
Additionally, , , , and \ were resolving to \ URLs because \ was not set (fixed separately by setting the env var).
Fix
Added a \ helper in \ that removes characters in the Stega Unicode ranges before values are used in meta tags:
Applied to , , and \ before they're inserted into any meta tags.
Verified
Tested on \ — all meta tags now contain clean, human-readable text with no zero-width characters.