From d7c5947da0ef130e7a3a33383246bededcb04ee3 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Thu, 23 Nov 2023 18:22:08 +0000 Subject: yaml: Escape all indicator characters. * ccwl/yaml.scm (display-atom): Escape strings if they contain any indicator character. --- ccwl/yaml.scm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ccwl/yaml.scm b/ccwl/yaml.scm index a33a88f..cc27be4 100644 --- a/ccwl/yaml.scm +++ b/ccwl/yaml.scm @@ -1,5 +1,5 @@ ;;; ccwl --- Concise Common Workflow Language -;;; Copyright © 2021 Arun Isaac +;;; Copyright © 2021, 2023 Arun Isaac ;;; ;;; This file is part of ccwl. ;;; @@ -54,10 +54,13 @@ serialized to YAML. Else, return @code{#f}." ;; specification. ;; Escape string with double quotes if ;; - every character is a digit or period, and the unescaped - ;; string can therefore be misinterpreted as a number - ;; - string contains the colon, hyphen or asterisk characters + ;; 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 (if (or (string-every (char-set-union char-set:digit (char-set #\.)) atom) - (string-any (char-set #\: #\- #\*) atom)) + (string-any (char-set #\- #\? #\: #\, #\[ #\] #\{ #\} #\# #\& + #\* #\! #\| #\> #\' #\" #\% #\@ #\`) + atom)) (write atom port) (display atom port))) ((boolean? atom) -- cgit v1.2.3