Cannot re-parse multi-line strings
j-shilling opened this issue · 2 comments
I'm running into an issue trying to encode multi-line strings and then parse them again. For example, when I run:
(-> "
build_the_package:
stage: build
script: |-
if [ -z \"${CUSTOM}\" ]; then
./mvnw package
fi
"
(yaml-parse-string :object-key-type 'string)
yaml-encode
yaml-parse-string)
I get a cryptic message "Unable to parse YAML stream. Parser finished before end of input 21/99." This seems to be because yaml-enocde
does not encode multi-line strings with the |-
syntax but instead escapes all the new lines:
(-> "
build_the_package:
stage: build
script: |-
if [ -z \"${CUSTOM}\" ]; then
./mvnw package
fi
"
(yaml-parse-string :object-key-type 'string)
yaml-encode)
;;=> "
;;=>build_the_package:
;;=> script: \"if [ -z \\\"${CUSTOM}\\\" ]; then\\n ./mvnw package\\nfi\"
;;=> stage: build"
Thanks for bringing this up! There was definitely a bug in the way that escape characters were being handled. I mistakenly put the parsing rule as ?\\
+ ?\n
as opposed to ?\\
+ ?n
. With this change in the round trip should work. I apologize for the cryptic error message though. I'll open a ticket for improving error messages of parsing errors.
Thanks @zkry ! My tests are now working--or at least, all the problems are on my end now.