You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JSON template parameters with control characters produce invalid script JSON #1038
processTemplateParams(..., isJson=true) escapes quotes, backslashes, and <, but leaves control characters such as newlines, tabs, and carriage returns unescaped. In a JSON script with processTemplateParams: true, inserting these values produces invalid JSON.
Reproduced on current main using the exported unhead/utils helper:
import{processTemplateParams}from'unhead/utils'constresult=processTemplateParams('{"name":"%value"}',{value: 'line1\nline2'},undefined,true,)JSON.parse(result)// SyntaxError: Bad control character in string literal
The same issue affects TemplateParamsPlugin for opted-in application/json and application/ld+json script content. JSON string control characters must be escaped (RFC 8259, section 7).
I plan to contribute a focused fix using JSON string escaping while retaining the existing < escaping. Regression tests will cover rendered SSR scripts, control-character round trips, quote/backslash/less-than handling, and unchanged plain-text substitutions. This work is AI-assisted.
Activity