Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot load empty file #10

Open
fbosio opened this issue Nov 22, 2020 · 0 comments
Open

Cannot load empty file #10

fbosio opened this issue Nov 22, 2020 · 0 comments

Comments

@fbosio
Copy link

fbosio commented Nov 22, 2020

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant