fix: correct rune handling in shouldQuoteIdentifier

This commit is contained in:
Andrei-hub11 2025-07-21 15:12:30 -03:00
parent b6fa663315
commit 1e075e0c3f
2 changed files with 2 additions and 12 deletions

View file

@ -303,24 +303,15 @@ func integerTypesToString(value interface{}) string {
} }
func shouldQuoteIdentifier(identifier string) bool { func shouldQuoteIdentifier(identifier string) bool {
if len(identifier) == 0 {
return true
}
_, err := strconv.ParseInt(identifier, 10, 64) _, err := strconv.ParseInt(identifier, 10, 64)
if err == nil { // if it is a number we should quote it if err == nil { // if it is a number we should quote it
return true return true
} }
firstChar := rune(identifier[0])
if unicode.IsNumber(firstChar) {
return true
}
// check if contains non ascii characters // check if contains non ascii characters
for _, c := range identifier { for i, c := range identifier {
if unicode.IsNumber(c) || c == '_' { if (unicode.IsNumber(c) && i > 0) || c == '_' {
continue continue
} }
if c > unicode.MaxASCII || !unicode.IsLetter(c) || unicode.IsUpper(c) { if c > unicode.MaxASCII || !unicode.IsLetter(c) || unicode.IsUpper(c) {

View file

@ -60,5 +60,4 @@ func TestShouldQuote(t *testing.T) {
require.Equal(t, shouldQuoteIdentifier("Abc_123"), true) require.Equal(t, shouldQuoteIdentifier("Abc_123"), true)
require.Equal(t, shouldQuoteIdentifier("DŽƜĐǶ"), true) require.Equal(t, shouldQuoteIdentifier("DŽƜĐǶ"), true)
require.Equal(t, shouldQuoteIdentifier("1test"), true) require.Equal(t, shouldQuoteIdentifier("1test"), true)
require.Equal(t, shouldQuoteIdentifier(""), true)
} }