Skip to content

Commit

Permalink
Merge #96501
Browse files Browse the repository at this point in the history
96501: randident: properly clamp unicode gen to 0-0x10FFFF r=stevendanna,ZhouXing19 a=knz

The last valid unicode character is 0x10FFFF, not 0xFFFFFFFF.

Release note: None
Epic: None

Co-authored-by: Raphael 'kena' Poss <[email protected]>
  • Loading branch information
craig[bot] and knz committed Feb 14, 2023
2 parents 16fd101 + d8daa53 commit 05d509a
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 05d509a

Please sign in to comment.