mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-29 10:16:26 -05:00
fix(template-function-json): escape control characters in json.escape (#607)
This commit is contained in:
@@ -85,7 +85,11 @@ export const plugin: PluginDefinition = {
|
||||
],
|
||||
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
|
||||
const input = String(args.values.input ?? "");
|
||||
return input.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
||||
// JSON.stringify produces a spec-correct string literal: it escapes
|
||||
// the backslash and quote this used to handle, and also the control
|
||||
// characters it did not. Slicing off the surrounding quotes leaves
|
||||
// the escaped inner text this function is meant to emit.
|
||||
return JSON.stringify(input).slice(1, -1);
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user