Skip to content

Commit c4a4557

Browse files
authored
Escape YAML for truthy values
Improve regex tests
1 parent 787fc33 commit c4a4557

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

trmnl-form-builder.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,9 +1729,14 @@ class TRMLYamlForm extends HTMLElement {
17291729
if (typeof value !== 'string') return '""';
17301730

17311731
// Check if value needs quoting
1732-
if (/[:#\[\]\{\},&\*\|>!'"%@`\n\t]/.test(value) || /^\d+$/.test(value) || value.startsWith(' ') || value.endsWith(' ')) {
1733-
return `"${value.replace(/"/g, '\\"')}"`;
1734-
}
1732+
if (
1733+
/[:#\[\]\{\},&\*\|>!'"%@`\n\t]/.test(value) || // Existing special chars
1734+
/^\d+$/.test(value) || // Existing numeric string check
1735+
value.startsWith(' ') || value.endsWith(' ') || // Existing whitespace check
1736+
/^(true|false|yes|no|on|off)$/i.test(value) // NEW check for YAML literals (case-insensitive)
1737+
){
1738+
return `"${value.replace(/"/g, '\\"')}"`;
1739+
};
17351740

17361741
return value;
17371742
}
@@ -2146,3 +2151,4 @@ class TRMLYamlForm extends HTMLElement {
21462151

21472152
// Register the custom element
21482153
customElements.define('trmnl-form-builder', TRMLYamlForm);
2154+

0 commit comments

Comments
 (0)