@@ -465,7 +465,6 @@ static php_mb_regex_t *php_mbregex_compile_pattern(const char *pattern, size_t p
465
465
OnigEncoding enc = MBREX (current_mbctype );
466
466
467
467
if (!php_mb_check_encoding (pattern , patlen , php_mb_regex_get_mbctype_encoding ())) {
468
- // TODO convert to ValueError after adding pattern_arg_num pass through argument
469
468
php_error_docref (NULL , E_WARNING ,
470
469
"Pattern is not valid under %s encoding" , _php_mb_regex_mbctype2name (enc ));
471
470
return NULL ;
@@ -475,7 +474,6 @@ static php_mb_regex_t *php_mbregex_compile_pattern(const char *pattern, size_t p
475
474
if (!rc || onig_get_options (rc ) != options || onig_get_encoding (rc ) != enc || onig_get_syntax (rc ) != syntax ) {
476
475
if ((err_code = onig_new (& retval , (OnigUChar * )pattern , (OnigUChar * )(pattern + patlen ), options , enc , syntax , & err_info )) != ONIG_NORMAL ) {
477
476
onig_error_code_to_str (err_str , err_code , & err_info );
478
- // Convert to error?
479
477
php_error_docref (NULL , E_WARNING , "mbregex compile err: %s" , err_str );
480
478
return NULL ;
481
479
}
@@ -929,6 +927,7 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
929
927
string_len ,
930
928
php_mb_regex_get_mbctype_encoding ()
931
929
)) {
930
+ // TODO return throw because invalid encoding?
932
931
RETURN_FALSE ;
933
932
}
934
933
@@ -1058,6 +1057,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
1058
1057
string_len ,
1059
1058
php_mb_regex_get_mbctype_encoding ()
1060
1059
)) {
1060
+ // TODO return throw because invalid encoding?
1061
1061
RETURN_NULL ();
1062
1062
}
1063
1063
@@ -1080,6 +1080,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
1080
1080
/* create regex pattern buffer */
1081
1081
re = php_mbregex_compile_pattern (arg_pattern , arg_pattern_len , options , syntax );
1082
1082
if (re == NULL ) {
1083
+ // Should this be considered an error instead?
1083
1084
RETURN_FALSE ;
1084
1085
}
1085
1086
@@ -1131,7 +1132,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
1131
1132
onig_region_free (regs , 1 );
1132
1133
smart_str_free (& out_buf );
1133
1134
smart_str_free (& eval_buf );
1134
- RETURN_FALSE ;
1135
+ RETURN_THROWS () ;
1135
1136
}
1136
1137
1137
1138
/* result of eval */
@@ -1169,8 +1170,9 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
1169
1170
zval_ptr_dtor (& retval );
1170
1171
} else {
1171
1172
if (!EG (exception )) {
1172
- // TODO Is this a return throw?
1173
- php_error_docref (NULL , E_WARNING , "Unable to call custom replacement function" );
1173
+ zend_throw_error (NULL , "Unable to call custom replacement function" );
1174
+ zval_ptr_dtor (& subpats );
1175
+ RETURN_THROWS ();
1174
1176
}
1175
1177
}
1176
1178
zval_ptr_dtor (& subpats );
@@ -1202,6 +1204,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
1202
1204
}
1203
1205
smart_str_free (& eval_buf );
1204
1206
1207
+ // Need to investigate if failure in Oniguruma and if should throw.
1205
1208
if (err <= -2 ) {
1206
1209
smart_str_free (& out_buf );
1207
1210
RETVAL_FALSE ;
@@ -1262,11 +1265,13 @@ PHP_FUNCTION(mb_split)
1262
1265
}
1263
1266
1264
1267
if (!php_mb_check_encoding (string , string_len , php_mb_regex_get_mbctype_encoding ())) {
1268
+ // TODO return throw because invalid encoding?
1265
1269
RETURN_FALSE ;
1266
1270
}
1267
1271
1268
1272
/* create regex pattern buffer */
1269
1273
if ((re = php_mbregex_compile_pattern (arg_pattern , arg_pattern_len , MBREX (regex_default_options ), MBREX (regex_default_syntax ))) == NULL ) {
1274
+ // TODO throw as invalid regex?
1270
1275
RETURN_FALSE ;
1271
1276
}
1272
1277
@@ -1303,6 +1308,7 @@ PHP_FUNCTION(mb_split)
1303
1308
onig_region_free (regs , 1 );
1304
1309
1305
1310
/* see if we encountered an error */
1311
+ // ToDo investigate if this can actually/should happen ...
1306
1312
if (err <= -2 ) {
1307
1313
OnigUChar err_str [ONIG_MAX_ERROR_MESSAGE_LEN ];
1308
1314
onig_error_code_to_str (err_str , err );
@@ -1356,10 +1362,12 @@ PHP_FUNCTION(mb_ereg_match)
1356
1362
}
1357
1363
1358
1364
if (!php_mb_check_encoding (string , string_len , php_mb_regex_get_mbctype_encoding ())) {
1365
+ // TODO return throw because invalid encoding?
1359
1366
RETURN_FALSE ;
1360
1367
}
1361
1368
1362
1369
if ((re = php_mbregex_compile_pattern (arg_pattern , arg_pattern_len , option , syntax )) == NULL ) {
1370
+ // TODO throw as invalid regex?
1363
1371
RETURN_FALSE ;
1364
1372
}
1365
1373
@@ -1416,6 +1424,7 @@ _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode)
1416
1424
if (arg_pattern ) {
1417
1425
/* create regex pattern buffer */
1418
1426
if ((MBREX (search_re ) = php_mbregex_compile_pattern (arg_pattern , arg_pattern_len , option , MBREX (regex_default_syntax ))) == NULL ) {
1427
+ // TODO throw as invalid regex?
1419
1428
RETURN_FALSE ;
1420
1429
}
1421
1430
}
@@ -1429,15 +1438,13 @@ _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode)
1429
1438
}
1430
1439
1431
1440
if (MBREX (search_re ) == NULL ) {
1432
- // TODO which Error/Exception to use, as this seems to be a logical error in function call ordering
1433
- php_error_docref (NULL , E_WARNING , "No regex given" );
1434
- RETURN_FALSE ;
1441
+ zend_throw_error (NULL , "No pattern was provided" );
1442
+ RETURN_THROWS ();
1435
1443
}
1436
1444
1437
1445
if (str == NULL ) {
1438
- // TODO which Error/Exception to use, as this seems to be a logical error in function call ordering
1439
- php_error_docref (NULL , E_WARNING , "No string given" );
1440
- RETURN_FALSE ;
1446
+ zend_throw_error (NULL , "No string was provided" );
1447
+ RETURN_THROWS ();
1441
1448
}
1442
1449
1443
1450
MBREX (search_regs ) = onig_region_new ();
@@ -1555,6 +1562,7 @@ PHP_FUNCTION(mb_ereg_search_init)
1555
1562
if (ZEND_NUM_ARGS () > 1 ) {
1556
1563
/* create regex pattern buffer */
1557
1564
if ((MBREX (search_re ) = php_mbregex_compile_pattern (arg_pattern , arg_pattern_len , option , syntax )) == NULL ) {
1565
+ // TODO throw as invalid regex?
1558
1566
RETURN_FALSE ;
1559
1567
}
1560
1568
}
@@ -1573,6 +1581,7 @@ PHP_FUNCTION(mb_ereg_search_init)
1573
1581
MBREX (search_pos ) = 0 ;
1574
1582
RETVAL_TRUE ;
1575
1583
} else {
1584
+ // TODO return throw because invalid encoding?
1576
1585
MBREX (search_pos ) = ZSTR_LEN (arg_str );
1577
1586
RETVAL_FALSE ;
1578
1587
}
@@ -1622,6 +1631,7 @@ PHP_FUNCTION(mb_ereg_search_getregs)
1622
1631
onig_foreach_name (MBREX (search_re ), mb_regex_groups_iter , & args );
1623
1632
}
1624
1633
} else {
1634
+ // TODO This seems to be some logical error, promote to Error
1625
1635
RETVAL_FALSE ;
1626
1636
}
1627
1637
}
0 commit comments