expression: fix painc on substring_index (#7806)
This commit is contained in:
@ -1210,6 +1210,11 @@ func (b *builtinSubstringIndexSig) evalString(row chunk.Row) (d string, isNull b
|
||||
} else {
|
||||
// If count is negative, everything to the right of the final delimiter (counting from the right) is returned.
|
||||
count = -count
|
||||
if count < 0 {
|
||||
// -count overflows max int64, returns an empty string.
|
||||
return "", false, nil
|
||||
}
|
||||
|
||||
if count < end {
|
||||
start = end - count
|
||||
}
|
||||
|
||||
@ -736,6 +736,7 @@ func (s *testIntegrationSuite) TestStringBuiltin(c *C) {
|
||||
result.Check(testkit.Rows("www.pingcap 12345 45 2017 01:01"))
|
||||
result = tk.MustQuery(`select substring_index('www.pingcap.com', '.', 0), substring_index('www.pingcap.com', '.', 100), substring_index('www.pingcap.com', '.', -100)`)
|
||||
result.Check(testkit.Rows(" www.pingcap.com www.pingcap.com"))
|
||||
tk.MustQuery(`select substring_index('xyz', 'abc', 9223372036854775808)`).Check(testkit.Rows(``))
|
||||
result = tk.MustQuery(`select substring_index('www.pingcap.com', 'd', 1), substring_index('www.pingcap.com', '', 1), substring_index('', '.', 1)`)
|
||||
result.Check(testutil.RowsWithSep(",", "www.pingcap.com,,"))
|
||||
result = tk.MustQuery(`select substring_index(null, '.', 1), substring_index('www.pingcap.com', null, 1), substring_index('www.pingcap.com', '.', null)`)
|
||||
|
||||
Reference in New Issue
Block a user