Recursion in getStatementStart could be a loop
Author: panziCreated Jun 9, 2024Updated Jun 9, 2024
Hey, I just noticed that the recursion here could be a simple loop, I think? (I'm new to Go, not new to programming.)
https://github.com/joho/godotenv/blob/3fc4292b58a67b78e1dbb6e47b4879a6cc602ec4/parser.go#L50-L68
Could be something like this:
func getStatementStart(src []byte) []byte {
for {
pos := indexOfNonSpaceChar(src)
if pos == -1 {
return nil
}
src = src[pos:]
if src[0] != charComment {
return src
}
// skip comment section
pos = bytes.IndexFunc(src, isCharFunc('\n'))
if pos == -1 {
return nil
}
src = src[pos:]
}
}This is not a bug, just something I noticed while reading the source in order to understand exactly what syntax this tool is accepting. Sorry for the noise.
Source: joho/godotenv