@@ -7275,12 +7275,12 @@ where
7275
7275
"create table charset_edge_test (c char(10), v varchar(20), t text);" ,
7276
7276
},
7277
7277
Assertions : []ScriptTestAssertion {
7278
- // STRICT MODE TESTS - Test formatInvalidByteForError function behavior
7278
+ // STRICT MODE TESTS
7279
7279
{
7280
7280
Query : "set sql_mode = 'STRICT_TRANS_TABLES';" ,
7281
7281
Expected : []sql.Row {{types.OkResult {RowsAffected : 0 }}},
7282
7282
},
7283
- // Test 1: Single invalid byte (0xAE) - tests basic formatInvalidByteForError
7283
+ // Single invalid byte (0xAE)
7284
7284
{
7285
7285
Query : "insert into charset_edge_test(c) values (UNHEX('AE'));" ,
7286
7286
ExpectedErrStr : "Incorrect string value: '\\ xAE' for column 'c' at row 1" ,
@@ -7293,17 +7293,17 @@ where
7293
7293
Query : "insert into charset_edge_test(t) values (UNHEX('AE'));" ,
7294
7294
ExpectedErrStr : "Incorrect string value: '\\ xAE' for column 't' at row 1" ,
7295
7295
},
7296
- // Test 2: Multiple invalid bytes - tests consecutive invalid byte handling
7296
+ // Multiple invalid bytes
7297
7297
{
7298
7298
Query : "insert into charset_edge_test(c) values (UNHEX('AEAEAE'));" ,
7299
7299
ExpectedErrStr : "Incorrect string value: '\\ xAE\\ xAE\\ xAE' for column 'c' at row 1" ,
7300
7300
},
7301
- // Test 3: Invalid bytes 0xC0, 0xC1 (overlong sequences)
7301
+ // Overlong sequences
7302
7302
{
7303
7303
Query : "insert into charset_edge_test(c) values (UNHEX('C0C1'));" ,
7304
7304
ExpectedErrStr : "Incorrect string value: '\\ xC0\\ xC1' for column 'c' at row 1" ,
7305
7305
},
7306
- // Test 4: Invalid bytes 0xFE, 0xFF (never valid UTF-8)
7306
+ // Invalid bytes 0xFE, 0xFF
7307
7307
{
7308
7308
Query : "insert into charset_edge_test(c) values (UNHEX('FE'));" ,
7309
7309
ExpectedErrStr : "Incorrect string value: '\\ xFE' for column 'c' at row 1" ,
@@ -7312,7 +7312,7 @@ where
7312
7312
Query : "insert into charset_edge_test(c) values (UNHEX('FF'));" ,
7313
7313
ExpectedErrStr : "Incorrect string value: '\\ xFF' for column 'c' at row 1" ,
7314
7314
},
7315
- // Test 5: Surrogate pairs (invalid in UTF-8)
7315
+ // Surrogate pairs
7316
7316
{
7317
7317
Query : "insert into charset_edge_test(c) values (UNHEX('EDA080'));" ,
7318
7318
ExpectedErrStr : "Incorrect string value: '\\ xED\\ xA0\\ x80' for column 'c' at row 1" ,
@@ -7321,7 +7321,7 @@ where
7321
7321
Query : "insert into charset_edge_test(c) values (UNHEX('EDBFBF'));" ,
7322
7322
ExpectedErrStr : "Incorrect string value: '\\ xED\\ xBF\\ xBF' for column 'c' at row 1" ,
7323
7323
},
7324
- // Test 6: Overlong sequences
7324
+ // More overlong sequences
7325
7325
{
7326
7326
Query : "insert into charset_edge_test(c) values (UNHEX('C080'));" ,
7327
7327
ExpectedErrStr : "Incorrect string value: '\\ xC0\\ x80' for column 'c' at row 1" ,
@@ -7334,12 +7334,12 @@ where
7334
7334
Query : "insert into charset_edge_test(c) values (UNHEX('F0808080'));" ,
7335
7335
ExpectedErrStr : "Incorrect string value: '\\ xF0\\ x80\\ x80\\ x80' for column 'c' at row 1" ,
7336
7336
},
7337
- // Test 7: Out of range (beyond U+10FFFF)
7337
+ // Out of range (beyond U+10FFFF)
7338
7338
{
7339
7339
Query : "insert into charset_edge_test(c) values (UNHEX('F4908080'));" ,
7340
7340
ExpectedErrStr : "Incorrect string value: '\\ xF4\\ x90\\ x80\\ x80' for column 'c' at row 1" ,
7341
7341
},
7342
- // Test 8: Continuation bytes without start byte
7342
+ // Continuation bytes without start byte
7343
7343
{
7344
7344
Query : "insert into charset_edge_test(c) values (UNHEX('80'));" ,
7345
7345
ExpectedErrStr : "Incorrect string value: '\\ x80' for column 'c' at row 1" ,
@@ -7348,7 +7348,7 @@ where
7348
7348
Query : "insert into charset_edge_test(c) values (UNHEX('BF'));" ,
7349
7349
ExpectedErrStr : "Incorrect string value: '\\ xBF' for column 'c' at row 1" ,
7350
7350
},
7351
- // Test 9: Incomplete sequences
7351
+ // Incomplete sequences
7352
7352
{
7353
7353
Query : "insert into charset_edge_test(c) values (UNHEX('C2'));" ,
7354
7354
ExpectedErrStr : "Incorrect string value: '\\ xC2' for column 'c' at row 1" ,
@@ -7361,28 +7361,26 @@ where
7361
7361
Query : "insert into charset_edge_test(c) values (UNHEX('F09080'));" ,
7362
7362
ExpectedErrStr : "Incorrect string value: '\\ xF0\\ x90\\ x80' for column 'c' at row 1" ,
7363
7363
},
7364
- // Test 10: Long sequence - tests truncation in formatInvalidByteForError (should show first 6 bytes + ...)
7364
+ // Long sequence ( tests truncation with ...)
7365
7365
{
7366
7366
Query : "insert into charset_edge_test(c) values (UNHEX('999897969594939291'));" ,
7367
7367
ExpectedErrStr : "Incorrect string value: '\\ x99\\ x98\\ x97\\ x96\\ x95\\ x94...' for column 'c' at row 1" ,
7368
7368
},
7369
- // Test 11: Valid UTF-8 with invalid bytes (mixed case) - tests position finding
7369
+ // Valid UTF-8 with invalid bytes
7370
7370
{
7371
7371
Query : "insert into charset_edge_test(c) values (UNHEX('446F6C744C6162AE'));" ,
7372
7372
ExpectedErrStr : "Incorrect string value: '\\ xAE' for column 'c' at row 1" ,
7373
7373
},
7374
7374
7375
- // NON-STRICT MODE TESTS - Should truncate invalid UTF-8 bytes
7375
+ // NON-STRICT MODE TESTS (should truncate)
7376
7376
{
7377
7377
Query : "set sql_mode = '';" ,
7378
7378
Expected : []sql.Row {{types.OkResult {RowsAffected : 0 }}},
7379
7379
},
7380
- // Test 12: Valid UTF-8 with invalid bytes should truncate
7381
7380
{
7382
7381
Query : "insert into charset_edge_test(c) values (UNHEX('446F6C744C6162AE'));" ,
7383
7382
Expected : []sql.Row {{types.OkResult {RowsAffected : 1 }}},
7384
7383
},
7385
- // Test 13: Multiple edge cases should truncate properly
7386
7384
{
7387
7385
Query : "insert into charset_edge_test(v) values (UNHEX('48656C6C6FC0'));" ,
7388
7386
Expected : []sql.Row {{types.OkResult {RowsAffected : 1 }}},
@@ -7391,7 +7389,7 @@ where
7391
7389
Query : "insert into charset_edge_test(t) values (UNHEX('54657374FF'));" ,
7392
7390
Expected : []sql.Row {{types.OkResult {RowsAffected : 1 }}},
7393
7391
},
7394
- // Test 14: Verify truncated data matches expected results
7392
+ // Verify truncated data
7395
7393
{
7396
7394
Query : "select HEX(c), LENGTH(c) from charset_edge_test where c is not null;" ,
7397
7395
Expected : []sql.Row {
@@ -7412,6 +7410,113 @@ where
7412
7410
},
7413
7411
},
7414
7412
},
7413
+ {
7414
+ Name : "charset validation ASCII range tests" ,
7415
+ SetUpScript : []string {
7416
+ "create table ascii_test (c char(10), v varchar(20), t text);" ,
7417
+ },
7418
+ Assertions : []ScriptTestAssertion {
7419
+ {
7420
+ Query : "set sql_mode = 'STRICT_TRANS_TABLES';" ,
7421
+ Expected : []sql.Row {{types.OkResult {RowsAffected : 0 }}},
7422
+ },
7423
+ // ASCII range 0x00-0x7F
7424
+ {
7425
+ Query : "insert into ascii_test(c) values (UNHEX('00'));" ,
7426
+ Expected : []sql.Row {{types.OkResult {RowsAffected : 1 }}},
7427
+ },
7428
+ {
7429
+ Query : "insert into ascii_test(c) values (UNHEX('20'));" ,
7430
+ Expected : []sql.Row {{types.OkResult {RowsAffected : 1 }}},
7431
+ },
7432
+ {
7433
+ Query : "insert into ascii_test(c) values (UNHEX('41'));" ,
7434
+ Expected : []sql.Row {{types.OkResult {RowsAffected : 1 }}},
7435
+ },
7436
+ {
7437
+ Query : "insert into ascii_test(c) values (UNHEX('7F'));" ,
7438
+ Expected : []sql.Row {{types.OkResult {RowsAffected : 1 }}},
7439
+ },
7440
+ {
7441
+ Query : "insert into ascii_test(v) values (UNHEX('48656C6C6F'));" , // "Hello"
7442
+ Expected : []sql.Row {{types.OkResult {RowsAffected : 1 }}},
7443
+ },
7444
+ {
7445
+ Query : "insert into ascii_test(t) values (UNHEX('00207F41'));" ,
7446
+ Expected : []sql.Row {{types.OkResult {RowsAffected : 1 }}},
7447
+ },
7448
+ // Verify ASCII data
7449
+ {
7450
+ Query : "select HEX(c), LENGTH(c) from ascii_test where c is not null order by c;" ,
7451
+ Expected : []sql.Row {
7452
+ {"00" , 1 },
7453
+ {"20" , 1 },
7454
+ {"41" , 1 },
7455
+ {"7F" , 1 },
7456
+ },
7457
+ },
7458
+ {
7459
+ Query : "select HEX(v), LENGTH(v) from ascii_test where v is not null;" ,
7460
+ Expected : []sql.Row {
7461
+ {"48656C6C6F" , 5 }, // "Hello"
7462
+ },
7463
+ },
7464
+ {
7465
+ Query : "select HEX(t), LENGTH(t) from ascii_test where t is not null;" ,
7466
+ Expected : []sql.Row {
7467
+ {"00207F41" , 4 }, // NULL + SPACE + DEL + A
7468
+ },
7469
+ },
7470
+ // Boundary cases
7471
+ {
7472
+ Query : "insert into ascii_test(c) values (UNHEX('7E'));" , // 0x7E is valid ASCII
7473
+ Expected : []sql.Row {{types.OkResult {RowsAffected : 1 }}},
7474
+ },
7475
+ {
7476
+ Query : "insert into ascii_test(c) values (UNHEX('81'));" , // 0x81 is invalid
7477
+ ExpectedErrStr : "Incorrect string value: '\\ x81' for column 'c' at row 1" ,
7478
+ },
7479
+ // Mixed ASCII and invalid (non-strict mode)
7480
+ {
7481
+ Query : "set sql_mode = '';" , // Non-strict mode
7482
+ Expected : []sql.Row {{types.OkResult {RowsAffected : 0 }}},
7483
+ },
7484
+ {
7485
+ Query : "insert into ascii_test(c) values (UNHEX('41424380'));" , // ABC + 0x80 (invalid)
7486
+ Expected : []sql.Row {{types.OkResult {RowsAffected : 1 }}},
7487
+ },
7488
+ // Verify truncation
7489
+ {
7490
+ Query : "select HEX(c), LENGTH(c) from ascii_test where HEX(c) = '414243';" ,
7491
+ Expected : []sql.Row {
7492
+ {"414243" , 3 }, // "ABC" - truncated at invalid byte
7493
+ },
7494
+ },
7495
+ // Valid UTF-8 sequences
7496
+ {
7497
+ Query : "set sql_mode = 'STRICT_TRANS_TABLES';" , // Back to strict mode
7498
+ Expected : []sql.Row {{types.OkResult {RowsAffected : 0 }}},
7499
+ },
7500
+ {
7501
+ Query : "insert into ascii_test(c) values (UNHEX('C3A9'));" , // é (2-byte UTF-8)
7502
+ Expected : []sql.Row {{types.OkResult {RowsAffected : 1 }}},
7503
+ },
7504
+ {
7505
+ Query : "insert into ascii_test(c) values (UNHEX('E282AC'));" , // € (3-byte UTF-8)
7506
+ Expected : []sql.Row {{types.OkResult {RowsAffected : 1 }}},
7507
+ },
7508
+ {
7509
+ Query : "insert into ascii_test(c) values (UNHEX('F09D849E'));" , // 𝄞 (4-byte UTF-8)
7510
+ Expected : []sql.Row {{types.OkResult {RowsAffected : 1 }}},
7511
+ },
7512
+ // Function boundary constants (asciiMin=32, asciiMax=127)
7513
+ {
7514
+ Query : "insert into ascii_test(c) values (UNHEX('1F'));" , // ASCII 31 (below asciiMin=32) - valid ASCII but non-printable
7515
+ Expected : []sql.Row {{types.OkResult {RowsAffected : 1 }}},
7516
+ },
7517
+ // Note: UNHEX('80') test is covered in edge cases test above
7518
+ },
7519
+ },
7415
7520
{
7416
7521
Name : "unix_timestamp script tests" ,
7417
7522
Dialect : "mysql" ,
0 commit comments