Skip to content
Snippets Groups Projects
Commit ee2ee025 authored by Junegunn Choi's avatar Junegunn Choi
Browse files

Fix index out of bounds error during Transform

parent b42dcdb7
No related branches found
No related tags found
No related merge requests found
......@@ -186,7 +186,13 @@ func Transform(tokens []Token, withNth []Range) *Transformed {
}
}
whole += part
transTokens[idx] = Token{&part, tokens[minIdx].prefixLength}
var prefixLength int
if minIdx < numTokens {
prefixLength = tokens[minIdx].prefixLength
} else {
prefixLength = 0
}
transTokens[idx] = Token{&part, prefixLength}
}
return &Transformed{
whole: &whole,
......
......@@ -95,3 +95,7 @@ func TestTransform(t *testing.T) {
}
}
}
func TestTransformIndexOutOfBounds(t *testing.T) {
Transform([]Token{}, splitNth("1"))
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment