Skip to content

Commit

Permalink
randident: properly clamp unicode gen to 0-0x10FFFF
Browse files Browse the repository at this point in the history
The last valid unicode character is 0x10FFFF, not 0xFFFFFFFF.

Release note: None
  • Loading branch information
knz committed Feb 13, 2023
1 parent f148476 commit d8daa53
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pkg/sql/logictest/testdata/logic_test/gen_test_objects
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ ORDER BY table_name, column_name
" u3" y text
"*t""1" "%56x" numeric
"*t""1" rowid bigint
"\\U3F862049u4" rowid bigint
"\\U3F862049u4" "y " text
"\\U00051024u4" rowid bigint
"\\U00051024u4" "y " text
"t%q3" rowid bigint
"t%q3" x numeric
t2 rowid bigint
Expand All @@ -148,7 +148,7 @@ ORDER BY table_name, constraint_name
----
" u3" pr̫imary
"*t""1" "PrimaRy̧"
"\\U3F862049u4" "primary"
"\\U00051024u4" "primary"
"t%q3" "primary"
t2 "primary"
t4 "primar'y"
Expand Down
3 changes: 2 additions & 1 deletion pkg/util/randident/namegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"math/rand"
"strconv"
"strings"
"unicode/utf8"

"github.com/cockroachdb/cockroach/pkg/sql/lexbase"
"github.com/cockroachdb/cockroach/pkg/util/randutil"
Expand Down Expand Up @@ -58,7 +59,7 @@ var escGenerators = []func(s *strings.Builder, r *rand.Rand){
func(s *strings.Builder, r *rand.Rand) { fmt.Fprintf(s, `%%%02x`, r.Int31n(256)) },
// SQL escape sequences.
func(s *strings.Builder, r *rand.Rand) { fmt.Fprintf(s, `\\u%04X`, r.Int31n(65536)) },
func(s *strings.Builder, r *rand.Rand) { fmt.Fprintf(s, `\\U%08X`, r.Uint32()) },
func(s *strings.Builder, r *rand.Rand) { fmt.Fprintf(s, `\\U%08X`, r.Int31n(utf8.MaxRune+1)) },
}

// GenerateOne generates one random name.
Expand Down

0 comments on commit d8daa53

Please sign in to comment.