Skip to content

Commit

Permalink
infoschema: fix FormatTiDBVersion panic (#39172)
Browse files Browse the repository at this point in the history
close #39059
  • Loading branch information
Defined2014 authored Nov 16, 2022
1 parent 6af4e4b commit 3e8899e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1729,8 +1729,8 @@ func FormatTiDBVersion(TiDBVersion string, isDefaultVersion bool) string {

// The user hasn't set the config 'ServerVersion'.
if isDefaultVersion {
nodeVersion = TiDBVersion[strings.LastIndex(TiDBVersion, "TiDB-")+len("TiDB-"):]
if nodeVersion[0] == 'v' {
nodeVersion = TiDBVersion[strings.Index(TiDBVersion, "TiDB-")+len("TiDB-"):]
if len(nodeVersion) > 0 && nodeVersion[0] == 'v' {
nodeVersion = nodeVersion[1:]
}
nodeVersions := strings.Split(nodeVersion, "-")
Expand Down
10 changes: 8 additions & 2 deletions infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,14 @@ func TestSelectHiddenColumn(t *testing.T) {

func TestFormatVersion(t *testing.T) {
// Test for defaultVersions.
defaultVersions := []string{"5.7.25-TiDB-None", "5.7.25-TiDB-8.0.18", "5.7.25-TiDB-8.0.18-beta.1", "5.7.25-TiDB-v4.0.0-beta-446-g5268094af"}
defaultRes := []string{"None", "8.0.18", "8.0.18-beta.1", "4.0.0-beta"}
defaultVersions := []string{
"5.7.25-TiDB-None",
"5.7.25-TiDB-8.0.18",
"5.7.25-TiDB-8.0.18-beta.1",
"5.7.25-TiDB-v4.0.0-beta-446-g5268094af",
"5.7.25-TiDB-",
"5.7.25-TiDB-v4.0.0-TiDB-446"}
defaultRes := []string{"None", "8.0.18", "8.0.18-beta.1", "4.0.0-beta", "", "4.0.0-TiDB"}
for i, v := range defaultVersions {
version := infoschema.FormatTiDBVersion(v, true)
require.Equal(t, defaultRes[i], version)
Expand Down

0 comments on commit 3e8899e

Please sign in to comment.