jm / toml

Parse TOML. Like a bawss.
MIT License
151 stars 38 forks source link

Fix issue with bare keys prefixed with # not being interpreted as a c… #63

Closed samaaron closed 3 years ago

samaaron commented 3 years ago

…omment line

From the Toml spec (https://toml.io/en/v1.0.0-rc.3):

_"Bare keys may only contain ASCII letters, ASCII digits, underscores, and dashes (A-Za-z0-9-). Note that bare keys are allowed to be composed of only ASCII digits, e.g. 1234, but are always interpreted as strings."__

This means the following should be interpreted as a comment line and not a value key/value pair:

#foobar = 3

However, as the toml gem codebase currently stands, this is interpreted as a string keyword which is typically represented in Toml with:

"#foobar" = 3

(As far as I could tell skimming the code base, only bare keys are currently supported anyway).

With this patch, we put precedence on comments, and therefore this matches a comment form rather than a keyword form earlier.

Note:

The rest of the tests still pass, although this precedence change could obviously have other ramifications that perhaps are not currently being tested.