@@ -134,7 +134,7 @@ objToEvents' (String s) rest =
134134 event
135135 -- Make sure that special strings are encoded as strings properly.
136136 -- See: https://github.com/snoyberg/yaml/issues/31
137− | s `HashSet.member` specialStrings = EventScalar (encodeUtf8 s) NoTag SingleQuoted Nothing
137+ | s `HashSet.member` specialStrings || isNumeric s = EventScalar (encodeUtf8 s) NoTag SingleQuoted Nothing
138138 | otherwise = EventScalar (encodeUtf8 s) StrTag PlainNoTag Nothing
139139objToEvents' Null rest = EventScalar "null" NullTag PlainNoTag Nothing : rest
140140objToEvents' (Bool True) rest = EventScalar "true" BoolTag PlainNoTag Nothing : rest
@@ -151,6 +151,16 @@ specialStrings :: HashSet.HashSet Text
151151specialStrings = HashSet.fromList $ T.words
152152 "y Y yes Yes YES n N no No NO true True TRUE false False FALSE on On ON off Off OFF null Null NULL ~"
153153
154+isNumeric :: Text -> Bool
155+isNumeric =
156+ T.all isNumeric'
157+ where
158+ isNumeric' c = ('0' <= c && c <= '9')
159+ || c == 'e'
160+ || c == 'E'
161+ || c == '.'
162+ || c == '-'
163+
154164-- Parsing
155165
156166data ParseException = NonScalarKey