fix(lua-rockspec): handle empty and whitespace-only rockspec files gracefully (#4827)

Empty or whitespace-only .rockspec files cause parseRockspecBlock to
panic with "index out of range" because the existing end-of-data guard
requires len(out) > 0 before returning the "unexpected end of block"
error, letting the bare data[*i] access on the next line crash.

Split the guard so that:
  - partial content at end of data still returns the existing error
  - empty data (or whitespace-only) returns an empty block cleanly

Closes #4824.

Signed-off-by: Akihiko Komada <aki1770@gmail.com>
This commit is contained in:
Akihiko Komada 2026-04-25 01:44:25 +09:00 committed by GitHub
parent 014a4c9c59
commit 3562dab445
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 2 deletions

View File

@ -63,8 +63,11 @@ func parseRockspecBlock(data []byte, i *int, locals map[string]string) ([]rocksp
parsing.SkipWhitespace(data, i) parsing.SkipWhitespace(data, i)
if *i >= len(data) && len(out) > 0 { if *i >= len(data) {
return nil, fmt.Errorf("unexpected end of block at %d", *i) if len(out) > 0 {
return nil, fmt.Errorf("unexpected end of block at %d", *i)
}
return out, nil
} }
c := data[*i] c := data[*i]

View File

@ -14,6 +14,17 @@ func Test_parseRockspecData(t *testing.T) {
content string content string
wantErr require.ErrorAssertionFunc wantErr require.ErrorAssertionFunc
}{ }{
{
name: "empty file",
content: ``,
},
{
name: "whitespace only",
content: `
`,
},
{ {
name: "basic valid content", name: "basic valid content",
content: ` content: `