@@ -3292,37 +3292,114 @@ normalize_table_name_low(
3292
3292
{
3293
3293
char * name_ptr;
3294
3294
char * db_ptr;
3295
+ ulint db_len;
3295
3296
char * ptr;
3296
3297
3297
3298
/* Scan name from the end */
3298
3299
3299
- ptr = strend (name)- 1 ;
3300
+ ptr = strend (name) - 1 ;
3300
3301
3302
+ /* seek to the last path separator */
3301
3303
while (ptr >= name && *ptr != ' \\ ' && *ptr != ' /' ) {
3302
3304
ptr--;
3303
3305
}
3304
3306
3305
3307
name_ptr = ptr + 1 ;
3306
3308
3307
- DBUG_ASSERT (ptr > name);
3309
+ /* skip any number of path separators */
3310
+ while (ptr >= name && (*ptr == ' \\ ' || *ptr == ' /' )) {
3311
+ ptr--;
3312
+ }
3308
3313
3309
- ptr-- ;
3314
+ DBUG_ASSERT ( ptr >= name) ;
3310
3315
3316
+ /* seek to the last but one path separator or one char before
3317
+ the beginning of name */
3318
+ db_len = 0 ;
3311
3319
while (ptr >= name && *ptr != ' \\ ' && *ptr != ' /' ) {
3312
3320
ptr--;
3321
+ db_len++;
3313
3322
}
3314
3323
3315
3324
db_ptr = ptr + 1 ;
3316
3325
3317
- memcpy (norm_name, db_ptr, strlen (name) + 1 - (db_ptr - name));
3326
+ memcpy (norm_name, db_ptr, db_len);
3327
+
3328
+ norm_name[db_len] = ' /' ;
3318
3329
3319
- norm_name[name_ptr - db_ptr - 1 ] = ' / ' ;
3330
+ memcpy ( norm_name + db_len + 1 , name_ptr, strlen (name_ptr) + 1 ) ;
3320
3331
3321
3332
if (set_lower_case) {
3322
3333
innobase_casedn_str (norm_name);
3323
3334
}
3324
3335
}
3325
3336
3337
+ #if !defined(DBUG_OFF)
3338
+ /* ********************************************************************
3339
+ Test normalize_table_name_low(). */
3340
+ static
3341
+ void
3342
+ test_normalize_table_name_low ()
3343
+ /* ===========================*/
3344
+ {
3345
+ char norm_name[128 ];
3346
+ const char * test_data[][2 ] = {
3347
+ /* input, expected result */
3348
+ {" ./mysqltest/t1" , " mysqltest/t1" },
3349
+ {" ./test/#sql-842b_2" , " test/#sql-842b_2" },
3350
+ {" ./test/#sql-85a3_10" , " test/#sql-85a3_10" },
3351
+ {" ./test/#sql2-842b-2" , " test/#sql2-842b-2" },
3352
+ {" ./test/bug29807" , " test/bug29807" },
3353
+ {" ./test/foo" , " test/foo" },
3354
+ {" ./test/innodb_bug52663" , " test/innodb_bug52663" },
3355
+ {" ./test/t" , " test/t" },
3356
+ {" ./test/t1" , " test/t1" },
3357
+ {" ./test/t10" , " test/t10" },
3358
+ {" /a/b/db/table" , " db/table" },
3359
+ {" /a/b/db///////table" , " db/table" },
3360
+ {" /a/b////db///////table" , " db/table" },
3361
+ {" /var/tmp/mysqld.1/#sql842b_2_10" , " mysqld.1/#sql842b_2_10" },
3362
+ {" db/table" , " db/table" },
3363
+ {" ddd/t" , " ddd/t" },
3364
+ {" d/ttt" , " d/ttt" },
3365
+ {" d/t" , " d/t" },
3366
+ {" .\\ mysqltest\\ t1" , " mysqltest/t1" },
3367
+ {" .\\ test\\ #sql-842b_2" , " test/#sql-842b_2" },
3368
+ {" .\\ test\\ #sql-85a3_10" , " test/#sql-85a3_10" },
3369
+ {" .\\ test\\ #sql2-842b-2" , " test/#sql2-842b-2" },
3370
+ {" .\\ test\\ bug29807" , " test/bug29807" },
3371
+ {" .\\ test\\ foo" , " test/foo" },
3372
+ {" .\\ test\\ innodb_bug52663" , " test/innodb_bug52663" },
3373
+ {" .\\ test\\ t" , " test/t" },
3374
+ {" .\\ test\\ t1" , " test/t1" },
3375
+ {" .\\ test\\ t10" , " test/t10" },
3376
+ {" C:\\ a\\ b\\ db\\ table" , " db/table" },
3377
+ {" C:\\ a\\ b\\ db\\\\\\\\\\\\\\ table" , " db/table" },
3378
+ {" C:\\ a\\ b\\\\\\\\ db\\\\\\\\\\\\\\ table" , " db/table" },
3379
+ {" C:\\ var\\ tmp\\ mysqld.1\\ #sql842b_2_10" , " mysqld.1/#sql842b_2_10" },
3380
+ {" db\\ table" , " db/table" },
3381
+ {" ddd\\ t" , " ddd/t" },
3382
+ {" d\\ ttt" , " d/ttt" },
3383
+ {" d\\ t" , " d/t" },
3384
+ };
3385
+
3386
+ for (size_t i = 0 ; i < UT_ARR_SIZE (test_data); i++) {
3387
+ printf (" test_normalize_table_name_low(): "
3388
+ " testing \" %s\" , expected \" %s\" ... " ,
3389
+ test_data[i][0 ], test_data[i][1 ]);
3390
+
3391
+ normalize_table_name_low (norm_name, test_data[i][0 ], FALSE );
3392
+
3393
+ if (strcmp (norm_name, test_data[i][1 ]) == 0 ) {
3394
+ printf (" ok\n " );
3395
+ } else {
3396
+ printf (" got \" %s\"\n " , norm_name);
3397
+ ut_error;
3398
+ }
3399
+ }
3400
+ }
3401
+ #endif /* !DBUG_OFF */
3402
+
3326
3403
/* *******************************************************************/ /* *
3327
3404
Get the upper limit of the MySQL integral and floating-point type.
3328
3405
@return maximum allowed value for the field */
@@ -7343,6 +7420,11 @@ ha_innobase::delete_table(
7343
7420
7344
7421
DBUG_ENTER (" ha_innobase::delete_table" );
7345
7422
7423
+ DBUG_EXECUTE_IF (
7424
+ " test_normalize_table_name_low" ,
7425
+ test_normalize_table_name_low ();
7426
+ );
7427
+
7346
7428
/* Strangely, MySQL passes the table name without the '.frm'
7347
7429
extension, in contrast to ::create */
7348
7430
normalize_table_name (norm_name, name);
0 commit comments