diff options
| -rw-r--r-- | ccwl/yaml.scm | 7 | ||||
| -rw-r--r-- | tests/yaml.scm | 8 |
2 files changed, 12 insertions, 3 deletions
diff --git a/ccwl/yaml.scm b/ccwl/yaml.scm index cc27be4..9ccd946 100644 --- a/ccwl/yaml.scm +++ b/ccwl/yaml.scm @@ -1,5 +1,5 @@ ;;; ccwl --- Concise Common Workflow Language -;;; Copyright © 2021, 2023 Arun Isaac <arunisaac@systemreboot.net> +;;; Copyright © 2021, 2023, 2026 Arun Isaac <arunisaac@systemreboot.net> ;;; ;;; This file is part of ccwl. ;;; @@ -57,10 +57,13 @@ serialized to YAML. Else, return @code{#f}." ;; string can therefore be misinterpreted as a number ;; - string contains indicator characters as mentioned in the YAML ;; spec https://yaml.org/spec/1.2.2/#53-indicator-characters + ;; - string contains whitespace characters other than space (if (or (string-every (char-set-union char-set:digit (char-set #\.)) atom) (string-any (char-set #\- #\? #\: #\, #\[ #\] #\{ #\} #\# #\& #\* #\! #\| #\> #\' #\" #\% #\@ #\`) - atom)) + atom) + (and (string-any char-set:whitespace atom) + (not (string-any #\space atom)))) (write atom port) (display atom port))) ((boolean? atom) diff --git a/tests/yaml.scm b/tests/yaml.scm index f9df12d..c475dd9 100644 --- a/tests/yaml.scm +++ b/tests/yaml.scm @@ -1,5 +1,5 @@ ;;; ccwl --- Concise Common Workflow Language -;;; Copyright © 2021, 2023 Arun Isaac <arunisaac@systemreboot.net> +;;; Copyright © 2021, 2023, 2026 Arun Isaac <arunisaac@systemreboot.net> ;;; ;;; This file is part of ccwl. ;;; @@ -41,6 +41,12 @@ bar: {} " (scm->yaml-string #("*foo" "*bar"))) +(test-equal "strings with whitespace characters other than space must be escaped" + "- \"foo\\nbar\" +- \"foo\\tbar\" +" + (scm->yaml-string #("foo\nbar" "foo\tbar"))) + (test-equal "single element vectors must be serialized on the same line" "[foo] " |
