dlang-community / toml

MIT License
4 stars 0 forks source link

TOML file that ends with comment crashes #7

Open katastic opened 1 month ago

katastic commented 1 month ago
[data]
    pygmentize = '2' # if we don't do our own

works fine (has newline after comment)

[data]
    pygmentize = '2' # if we don't do our own

crashes with off-by-one error. (github inserts a newline there, there is no newline on the second example after comment)

toml\src\toml\toml.d(1007): index [328] is out of bounds for array of length 328

code here:

void readKeyValue(string[] keys) {
      if (clear()) {
         enforceParser(data[index++] == '=', "Expected '=' after key declaration");
         if (clear!false()) {
            set(keys, readValue());
            // there must be nothing after the key/value declaration except comments and whitespaces
            if (clear!false())
1007:           enforceParser(data[index] == '\n', "Invalid characters after value declaration: " ~ data[index]);
katastic commented 1 month ago

This TOML might violate the spec, but there should be a proper error then, not a random range violation. I only see warnings about newlines after keyvalue pairs though: image