From 213345740ab25a245d1c9c9f82016b1183f67d64 Mon Sep 17 00:00:00 2001 From: Mario Lurig Date: Mon, 22 Dec 2025 12:09:06 -0700 Subject: [PATCH] Fixes Issue #7 --- tests/yaml-operations.test.js | 22 ++++++++++++++++++++++ trmnl-form-builder.js | 6 ++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/yaml-operations.test.js b/tests/yaml-operations.test.js index a8c16c1..95cd5a8 100644 --- a/tests/yaml-operations.test.js +++ b/tests/yaml-operations.test.js @@ -214,6 +214,28 @@ describe('TRMNL Form Builder - YAML Operations', () => { expect(yaml).toBe('# No fields defined yet') }) + + it('should quote boolean literal labels in options', () => { + element.fields = [{ + id: 'field_1', + keyname: 'show_email', + field_type: 'select', + name: 'Show Email', + options: [ + { 'Yes': 'yes' }, + { 'No': 'no' }, + { 'True': 'true' }, + { 'False': 'false' } + ] + }] + + const yaml = element.generateYaml() + + expect(yaml).toContain('"Yes": "yes"') + expect(yaml).toContain('"No": "no"') + expect(yaml).toContain('"True": "true"') + expect(yaml).toContain('"False": "false"') + }) }) describe('Helper Methods', () => { diff --git a/trmnl-form-builder.js b/trmnl-form-builder.js index 5371e18..99e8f4c 100644 --- a/trmnl-form-builder.js +++ b/trmnl-form-builder.js @@ -1658,8 +1658,10 @@ class TRMLYamlForm extends HTMLElement { if (typeof opt === 'object') { // Label:Value pair - format as YAML key:value const [label, value] = Object.entries(opt)[0]; - // Don't escape the label in the key position, only the value - lines.push(` - ${label}: ${this.escapeYaml(value)}`); + // Escape both label and value to handle boolean literals + const escapedLabel = this.escapeYaml(label); + const escapedValue = this.escapeYaml(value); + lines.push(` - ${escapedLabel}: ${escapedValue}`); } else { // Simple string lines.push(` - ${this.escapeYaml(opt)}`);