Skip to content

Cannot load empty file #10

@fbosio

Description

@fbosio

We're making some tests with the busted module and an empty yaml file is used in it, but the test raises an error.

How to reproduce this issue

Just run

local yaml = require "tinyyaml"
local t = yaml.parse("")

Expected result

t should be an empty table.

Obtained error

lua: ./tinyyaml.lua:684: bad argument #1 to 'sfind' (string expected, got nil)

Proposed fix

Add

if #lines == 0 then return {} end 

below line 684 of tinyyaml.lua.

Edit

The above doesn't take into account the case of a non-empty file that has comments only. A better fix would be

if sfind(lines[1] or "", '^%%YAML') then tremove(lines, 1) end

in line 704, i.e., add or "" next to if sfind(lines[1] (suggested by @gabrielbosio).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions