Skip to content

fix: prevent panic in isArrayKey when node name is empty string - #67

Merged
mmatur merged 1 commit into
traefik:masterfrom
mmatur:fix/isarraykey-empty-string
Jun 27, 2026
Merged

mmatur merged 1 commit into
traefik:masterfrom
mmatur:fix/isarraykey-empty-string

Conversation

@mmatur

@mmatur mmatur commented Jun 27, 2026

Copy link
Copy Markdown
Member

Summary

isArrayKey accessed name[0] without checking len(name) > 0 first, causing an index out of range panic when processing a YAML manifest with an empty string map key (e.g. "": value).

Root cause

// before
func isArrayKey(name string) bool {
    return name[0] == '[' && name[len(name)-1] == ']'  // panics when name == ""
}

// after
func isArrayKey(name string) bool {
    return len(name) > 0 && name[0] == '[' && name[len(name)-1] == ']'
}

Test

Added a test case in Test_nodeToRawMap with an empty string key to cover this path.

isArrayKey accessed name[0] without checking len(name) first,
causing an index out of range panic when a YAML map has an empty string key.
@mmatur
mmatur merged commit 7405e0d into traefik:master Jun 27, 2026
4 checks passed
@mmatur
mmatur deleted the fix/isarraykey-empty-string branch June 27, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant