Skip to content

Do not panic on an empty entry in the repositories block - #2042

Open
arpitjain099 wants to merge 1 commit into
wolfi-dev:mainfrom
arpitjain099:fix/empty-repository-entry
Open

arpitjain099 wants to merge 1 commit into
wolfi-dev:mainfrom
arpitjain099:fix/empty-repository-entry

Conversation

@arpitjain099

Copy link
Copy Markdown

The tagged-repository-in-environment-repos rule reads repo[0] on every entry of environment.contents.repositories and buildRepositories. An empty string entry is easy to produce with a stray dash in the YAML, and it makes the linter panic on the very file it was asked to lint:

panic: runtime error: index out of range [0] with length 0

strings.HasPrefix(repo, "@") is what the check means anyway, and it is safe on an empty string.

Added a empty-repository-entry.yaml fixture whose repositories block has one empty entry. It panics on main and passes here. The existing forbidden-repository-tagged.yaml case still reports the tagged repository as before, so the rule itself is unchanged for real input.

The tagged-repository-in-environment-repos rule indexes repo[0] on every
entry of environment.contents.repositories and buildRepositories. An empty
string entry, which is easy to produce with a stray dash in the YAML, made
the linter panic on the file it was asked to lint:

    panic: runtime error: index out of range [0] with length 0

Use strings.HasPrefix instead, which is what the check means anyway.

Adds a fixture with an empty entry; it panics without the change.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
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

Successfully merging this pull request may close these issues.

1 participant