flyx / NimYAML

YAML implementation for Nim
https://nimyaml.org
Other
186 stars 36 forks source link

Strings of length >= 80 with a single non-space character serialize to invalid YAML #105

Closed quantimnot closed 2 years ago

quantimnot commented 2 years ago
import yaml, strutils
var str = dump(repeat("00 ", 27))
echo str # valid
load(str, str) # works
str = dump(repeat("0 ", 40))
echo str # invalid
load(str, str) # fails

# output
#
# %YAML 1.2
# %TAG !n! tag:nimyaml.org,2016:
# ---
# !!str >-
#   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
# %YAML 1.2
# %TAG !n! tag:nimyaml.org,2016:
# ---
# !!str >- 0
#   0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# [NimYAML] Error in file serialization.nim at line 1355:
# Unexpected exception: LexerError
# … stacktrace [YamlStreamError: Illegal character after block scalar header: "0"]
flyx commented 2 years ago

Pretty sure this fixes it, but I currently don't have a working Nim dev env so please test and report back!

(you can nimble install yaml#head to get this fix)

quantimnot commented 2 years ago

Thank you! I was juuust getting into that proc :)