Problem
token.QuoteSQLIdent("") panics with an index-out-of-range error because needQuoteSQLIdent reads s[0] without first checking whether s is empty.
panic: runtime error: index out of range [0] with length 0
The same panic is reachable indirectly through an exported AST node:
Reproduction
token.QuoteSQLIdent("")
https://go.dev/play/p/vniPESiuWGD
package main
import "github.com/cloudspannerecosystem/memefish/token"
func main() {
_ = token.QuoteSQLIdent("")
}
(*ast.Ident).SQL()
https://go.dev/play/p/Jp6w9qpqLfE
package main
import "github.com/cloudspannerecosystem/memefish/ast"
func main() {
_ = (&ast.Ident{Name: ""}).SQL()
}
Why change this
The function returns only a string and documents no non-empty precondition. Downstream code that constructs ast.Ident values from runtime strings must currently validate every identifier before serialization or recover at a broader boundary.
This follows the separation in google/googlesql: ParseIdentifier rejects an empty backquoted identifier, while ToIdentifierLiteral("") returns two backticks and explicitly notes that the result is not a valid identifier.
Expected behavior
QuoteSQLIdent("") returns two backticks instead of panicking. Identifier validation remains unchanged; empty identifiers are still rejected by the lexer/parser.
Problem
token.QuoteSQLIdent("")panics with an index-out-of-range error becauseneedQuoteSQLIdentreadss[0]without first checking whethersis empty.The same panic is reachable indirectly through an exported AST node:
Reproduction
token.QuoteSQLIdent("")https://go.dev/play/p/vniPESiuWGD
(*ast.Ident).SQL()https://go.dev/play/p/Jp6w9qpqLfE
Why change this
The function returns only a string and documents no non-empty precondition. Downstream code that constructs
ast.Identvalues from runtime strings must currently validate every identifier before serialization or recover at a broader boundary.This follows the separation in
google/googlesql:ParseIdentifierrejects an empty backquoted identifier, whileToIdentifierLiteral("")returns two backticks and explicitly notes that the result is not a valid identifier.Expected behavior
QuoteSQLIdent("")returns two backticks instead of panicking. Identifier validation remains unchanged; empty identifiers are still rejected by the lexer/parser.