Repository: pingcap/tidb (Go)

Issue:
`IS_UUID` and `UUID_TO_BIN` shouldn't trim the argument
## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

<!-- a step by step guide for reproducing the bug. -->

### 2. What did you expect to see? (Required)

```
mysql> SELECT IS_UUID(' 6ccd780c-baba-1026-8567-4cc3505b2a62 ');
+---------------------------------------------------+
| IS_UUID(' 6ccd780c-baba-1026-8567-4cc3505b2a62 ') |
+---------------------------------------------------+
|                                                 0 |
+---------------------------------------------------+
1 row in set (0.03 sec)

mysql> SELECT UUID_TO_BIN(' 6ccd780c-baba-1026-9564-5b8c656024db ');
ERROR 1411 (HY000): Incorrect string value: ' 6ccd780c-baba-1026-9564-5b8c656024db ' for function uuid_to_bin
```

### 3. What did you see instead (Required)

```
mysql> SELECT IS_UUID(' 6ccd780c-baba-1026-8567-4cc3505b2a62 ');
+---------------------------------------------------+
| IS_UUID(' 6ccd780c-baba-1026-8567-4cc3505b2a62 ') |
+---------------------------------------------------+
|                                                 1 |
+---------------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT UUID_TO_BIN(' 6ccd780c-baba-1026-9564-5b8c656024db ');
+--------------------------------------------------------------------------------------------------------------+
| UUID_TO_BIN(' 6ccd780c-baba-1026-9564-5b8c656024db ')                                                        |
+--------------------------------------------------------------------------------------------------------------+
| 0x6CCD780CBABA102695645B8C656024DB                                                                           |
+--------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```

### 4. What is your TiDB version? (Required)

<!-- Paste the output of SELECT tidb_version() -->




Discussion: /severity moderate



Fix (patch):
diff --git a/pkg/expression/builtin_miscellaneous.go b/pkg/expression/builtin_miscellaneous.go
index 2dcc828ef0b61..9de055363c34e 100644
--- a/pkg/expression/builtin_miscellaneous.go
+++ b/pkg/expression/builtin_miscellaneous.go
@@ -1220,6 +1220,11 @@ func (b *builtinIsUUIDSig) evalInt(ctx EvalContext, row chunk.Row) (int64, bool,
 	if err != nil || isNull {
 		return 0, isNull, err
 	}
+	// MySQL's IS_UUID is strict and doesn't trim spaces, unlike Go's uuid.Parse
+	// We need to check if the string has leading/trailing spaces before parsing
+	if strings.TrimSpace(val) != val {
+		return 0, false, nil
+	}
 	if _, err = uuid.Parse(val); err != nil {
 		return 0, false, nil
 	}
@@ -1606,6 +1611,12 @@ func (b *builtinUUIDToBinSig) evalString(ctx EvalContext, row chunk.Row) (string
 		return "", isNull, err
 	}
 
+	// MySQL's UUID_TO_BIN is strict and doesn't trim spaces, unlike Go's uuid.Parse
+	// We need to check if the string has leading/trailing spaces before parsing
+	if strings.TrimSpace(val) != val {
+		return "", false, errWrongValueForType.GenWithStackByArgs("string", val, "uuid_to_bin")
+	}
+
 	u, err := uuid.Parse(val)
 	if err != nil {
 		return "", false, errWrongValueForType.GenWithStackByArgs("string", val, "uuid_to_bin")
diff --git a/pkg/expression/builtin_miscellaneous_vec.go b/pkg/expression/builtin_miscellaneous_vec.go
index a4d5fbe008d62..bb3b9abfbbe6b 100644
--- a/pkg/expression/builtin_miscellaneous_vec.go
+++ b/pkg/expression/builtin_miscellaneous_vec.go
@@ -170,7 +170,12 @@ func (b *builtinIsUUIDSig) vecEvalInt(ctx EvalContext, input *chunk.Chunk, resul
 		if result.IsNull(i) {
 			continue
 		}
-		if _, err = uuid.Parse(buf.GetString(i)); err != nil {
+		val := buf.GetString(i)
+		// MySQL's IS_UUID is strict and doesn't trim spaces, unlike Go's uuid.Parse
+		// We need to check if the string has leading/trailing spaces before parsing
+		if strings.TrimSpace(val) != val {
+			i64s[i] = 0
+		} else if _, err = uuid.Parse(val); err != nil {
 			i64s[i] = 0
 		} else {
 			i64s[i] = 1
@@ -695,6 +700,11 @@ func (b *builtinUUIDToBinSig) vecEvalString(ctx EvalContext, input *chunk.Chunk,
 			continue
 		}
 		val := valBuf.GetString(i)
+		// MySQL's UUID_TO_BIN is strict and doesn't trim spaces, unlike Go's uuid.Parse
+		// We need to check if the string has leading/trailing spaces before parsing
+		if strings.TrimSpace(val) != val {
+			return errWrongValueForType.GenWithStackByArgs("string", val, "uuid_to_bin")
+		}
 		u, err := uuid.Parse(val)
 		if err != nil {
 			return errWrongValueForType.GenWithStackByArgs("string", val, "uuid_to_bin")