@@ -1360,6 +1360,46 @@ void test_gh_5362() {
1360
1360
test_gh_5362_grep ();
1361
1361
}
1362
1362
1363
+ void test_gh_5364 () {
1364
+ // GH-5364 <regex>: Allow initial ] to start character ranges in POSIX regular expressions
1365
+ for (syntax_option_type option : {basic, extended, awk, grep, egrep}) {
1366
+ g_regexTester.should_match (" ]" , " []-_]" , option);
1367
+ g_regexTester.should_match (" ^" , " []-_]" , option);
1368
+ g_regexTester.should_match (" _" , " []-_]" , option);
1369
+ g_regexTester.should_not_match (" -" , " []-_]" , option);
1370
+
1371
+ g_regexTester.should_not_match (" ]" , " [^]-_]" , option);
1372
+ g_regexTester.should_not_match (" ^" , " [^]-_]" , option);
1373
+ g_regexTester.should_not_match (" _" , " [^]-_]" , option);
1374
+ g_regexTester.should_match (" -" , " [^]-_]" , option);
1375
+
1376
+ g_regexTester.should_match (" ]" , " []a]" , option);
1377
+ g_regexTester.should_match (" a" , " []a]" , option);
1378
+ g_regexTester.should_not_match (" _" , " []a]" , option);
1379
+ g_regexTester.should_not_match (" a]" , " []a]" , option);
1380
+ g_regexTester.should_not_match (" ]a" , " []a]" , option);
1381
+ g_regexTester.should_not_match (" __" , " []a]" , option);
1382
+
1383
+ g_regexTester.should_not_match (" ]" , " [^]a]" , option);
1384
+ g_regexTester.should_not_match (" a" , " [^]a]" , option);
1385
+ g_regexTester.should_match (" _" , " [^]a]" , option);
1386
+ g_regexTester.should_not_match (" a]" , " [^]a]" , option);
1387
+ g_regexTester.should_not_match (" ]a" , " [^]a]" , option);
1388
+ g_regexTester.should_not_match (" __" , " [^]a]" , option);
1389
+
1390
+ g_regexTester.should_throw (" []" , error_brack, option);
1391
+ g_regexTester.should_throw (" [^]" , error_brack, option);
1392
+ }
1393
+
1394
+ g_regexTester.should_throw (" []-_]" , error_brack, ECMAScript);
1395
+ g_regexTester.should_throw (" [^]-_]" , error_brack, ECMAScript);
1396
+ g_regexTester.should_throw (" []a]" , error_brack, ECMAScript);
1397
+ g_regexTester.should_throw (" [^]a]" , error_brack, ECMAScript);
1398
+
1399
+ g_regexTester.should_not_match (" c" , " []" , ECMAScript);
1400
+ g_regexTester.should_match (" c" , " [^]" , ECMAScript);
1401
+ }
1402
+
1363
1403
int main () {
1364
1404
test_dev10_449367_case_insensitivity_should_work ();
1365
1405
test_dev11_462743_regex_collate_should_not_disable_regex_icase ();
@@ -1398,6 +1438,7 @@ int main() {
1398
1438
test_gh_5214 ();
1399
1439
test_gh_5253 ();
1400
1440
test_gh_5362 ();
1441
+ test_gh_5364 ();
1401
1442
1402
1443
return g_regexTester.result ();
1403
1444
}
0 commit comments