@@ -591,8 +591,8 @@ static size_t _php_mb_regex_get_option_string(char *str, size_t len, OnigOptionT
591
591
/* }}} */
592
592
593
593
/* {{{ _php_mb_regex_init_options */
594
- static void
595
- _php_mb_regex_init_options ( const char * parg , size_t narg , OnigOptionType * option , OnigSyntaxType * * syntax , int * eval )
594
+ static bool _php_mb_regex_init_options ( const char * parg , size_t narg , OnigOptionType * option ,
595
+ OnigSyntaxType * * syntax )
596
596
{
597
597
size_t n ;
598
598
char c ;
@@ -650,15 +650,14 @@ _php_mb_regex_init_options(const char *parg, size_t narg, OnigOptionType *option
650
650
case 'd' :
651
651
* syntax = ONIG_SYNTAX_POSIX_EXTENDED ;
652
652
break ;
653
- case 'e' :
654
- if (eval != NULL ) * eval = 1 ;
655
- break ;
656
653
default :
657
- break ;
654
+ zend_value_error ("Option \"%c\" is not supported" , c );
655
+ return false;
658
656
}
659
657
}
660
658
if (option != NULL ) * option |=optm ;
661
659
}
660
+ return true;
662
661
}
663
662
/* }}} */
664
663
@@ -900,6 +899,11 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
900
899
RETURN_THROWS ();
901
900
}
902
901
902
+ if (arg_pattern_len == 0 ) {
903
+ zend_argument_value_error (1 , "must not be empty" );
904
+ RETURN_THROWS ();
905
+ }
906
+
903
907
if (array != NULL ) {
904
908
array = zend_try_array_init (array );
905
909
if (!array ) {
@@ -920,12 +924,6 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
920
924
options |= ONIG_OPTION_IGNORECASE ;
921
925
}
922
926
923
- if (arg_pattern_len == 0 ) {
924
- php_error_docref (NULL , E_WARNING , "Empty pattern" );
925
- RETVAL_FALSE ;
926
- goto out ;
927
- }
928
-
929
927
re = php_mbregex_compile_pattern (arg_pattern , arg_pattern_len , options , MBREX (regex_default_syntax ));
930
928
if (re == NULL ) {
931
929
RETVAL_FALSE ;
@@ -1007,15 +1005,14 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
1007
1005
smart_str out_buf = {0 };
1008
1006
smart_str eval_buf = {0 };
1009
1007
smart_str * pbuf ;
1010
- int err , eval , n ;
1008
+ int err , n ;
1011
1009
OnigUChar * pos ;
1012
1010
OnigUChar * string_lim ;
1013
1011
char * description = NULL ;
1014
1012
1015
1013
const mbfl_encoding * enc = php_mb_regex_get_mbctype_encoding ();
1016
1014
ZEND_ASSERT (enc != NULL );
1017
1015
1018
- eval = 0 ;
1019
1016
{
1020
1017
char * option_str = NULL ;
1021
1018
size_t option_str_len = 0 ;
@@ -1043,20 +1040,15 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
1043
1040
}
1044
1041
1045
1042
if (option_str != NULL ) {
1046
- _php_mb_regex_init_options (option_str , option_str_len , & options , & syntax , & eval );
1043
+ /* Initialize option and in case of failure it means there is a value error */
1044
+ if (!_php_mb_regex_init_options (option_str , option_str_len , & options , & syntax )) {
1045
+ RETURN_THROWS ();
1046
+ }
1047
1047
} else {
1048
1048
options |= MBREX (regex_default_options );
1049
1049
syntax = MBREX (regex_default_syntax );
1050
1050
}
1051
1051
}
1052
- if (eval ) {
1053
- if (is_callable ) {
1054
- php_error_docref (NULL , E_WARNING , "Option 'e' cannot be used with replacement callback" );
1055
- } else {
1056
- php_error_docref (NULL , E_WARNING , "The 'e' option is no longer supported, use mb_ereg_replace_callback instead" );
1057
- }
1058
- RETURN_FALSE ;
1059
- }
1060
1052
1061
1053
/* create regex pattern buffer */
1062
1054
re = php_mbregex_compile_pattern (arg_pattern , arg_pattern_len , options , syntax );
@@ -1122,7 +1114,9 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
1122
1114
zval_ptr_dtor (& retval );
1123
1115
} else {
1124
1116
if (!EG (exception )) {
1125
- php_error_docref (NULL , E_WARNING , "Unable to call custom replacement function" );
1117
+ zend_throw_error (NULL , "Unable to call custom replacement function" );
1118
+ zval_ptr_dtor (& subpats );
1119
+ RETURN_THROWS ();
1126
1120
}
1127
1121
}
1128
1122
zval_ptr_dtor (& subpats );
@@ -1251,6 +1245,7 @@ PHP_FUNCTION(mb_split)
1251
1245
onig_region_free (regs , 1 );
1252
1246
1253
1247
/* see if we encountered an error */
1248
+ // ToDo investigate if this can actually/should happen ...
1254
1249
if (err <= -2 ) {
1255
1250
OnigUChar err_str [ONIG_MAX_ERROR_MESSAGE_LEN ];
1256
1251
onig_error_code_to_str (err_str , err );
@@ -1295,7 +1290,9 @@ PHP_FUNCTION(mb_ereg_match)
1295
1290
}
1296
1291
1297
1292
if (option_str != NULL ) {
1298
- _php_mb_regex_init_options (option_str , option_str_len , & option , & syntax , NULL );
1293
+ if (!_php_mb_regex_init_options (option_str , option_str_len , & option , & syntax )) {
1294
+ RETURN_THROWS ();
1295
+ }
1299
1296
} else {
1300
1297
option |= MBREX (regex_default_options );
1301
1298
syntax = MBREX (regex_default_syntax );
@@ -1348,7 +1345,7 @@ static void _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mod
1348
1345
}
1349
1346
1350
1347
if (arg_options ) {
1351
- _php_mb_regex_init_options (arg_options , arg_options_len , & option , & syntax , NULL );
1348
+ _php_mb_regex_init_options (arg_options , arg_options_len , & option , & syntax );
1352
1349
} else {
1353
1350
option |= MBREX (regex_default_options );
1354
1351
syntax = MBREX (regex_default_syntax );
@@ -1375,13 +1372,13 @@ static void _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mod
1375
1372
}
1376
1373
1377
1374
if (MBREX (search_re ) == NULL ) {
1378
- php_error_docref (NULL , E_WARNING , "No regex given " );
1379
- RETURN_FALSE ;
1375
+ zend_throw_error (NULL , "No pattern was provided " );
1376
+ RETURN_THROWS () ;
1380
1377
}
1381
1378
1382
1379
if (str == NULL ) {
1383
- php_error_docref (NULL , E_WARNING , "No string given " );
1384
- RETURN_FALSE ;
1380
+ zend_throw_error (NULL , "No string was provided " );
1381
+ RETURN_THROWS () ;
1385
1382
}
1386
1383
1387
1384
MBREX (search_regs ) = onig_region_new ();
@@ -1480,13 +1477,13 @@ PHP_FUNCTION(mb_ereg_search_init)
1480
1477
}
1481
1478
1482
1479
if (arg_pattern && arg_pattern_len == 0 ) {
1483
- php_error_docref ( NULL , E_WARNING , "Empty pattern " );
1484
- RETURN_FALSE ;
1480
+ zend_argument_value_error ( 2 , "must not be empty " );
1481
+ RETURN_THROWS () ;
1485
1482
}
1486
1483
1487
1484
if (arg_options ) {
1488
1485
option = 0 ;
1489
- _php_mb_regex_init_options (arg_options , arg_options_len , & option , & syntax , NULL );
1486
+ _php_mb_regex_init_options (arg_options , arg_options_len , & option , & syntax );
1490
1487
} else {
1491
1488
option = MBREX (regex_default_options );
1492
1489
syntax = MBREX (regex_default_syntax );
@@ -1557,6 +1554,7 @@ PHP_FUNCTION(mb_ereg_search_getregs)
1557
1554
onig_foreach_name (MBREX (search_re ), mb_regex_groups_iter , & args );
1558
1555
}
1559
1556
} else {
1557
+ // TODO This seems to be some logical error, promote to Error
1560
1558
RETVAL_FALSE ;
1561
1559
}
1562
1560
}
@@ -1588,12 +1586,12 @@ PHP_FUNCTION(mb_ereg_search_setpos)
1588
1586
}
1589
1587
1590
1588
if (position < 0 || (!Z_ISUNDEF (MBREX (search_str )) && Z_TYPE (MBREX (search_str )) == IS_STRING && (size_t )position > Z_STRLEN (MBREX (search_str )))) {
1591
- php_error_docref (NULL , E_WARNING , "Position is out of range" );
1592
- MBREX (search_pos ) = 0 ;
1593
- RETURN_FALSE ;
1589
+ zend_argument_value_error (1 , "is out of range" );
1590
+ RETURN_THROWS ();
1594
1591
}
1595
1592
1596
1593
MBREX (search_pos ) = position ;
1594
+ // TODO Return void
1597
1595
RETURN_TRUE ;
1598
1596
}
1599
1597
/* }}} */
@@ -1628,7 +1626,9 @@ PHP_FUNCTION(mb_regex_set_options)
1628
1626
if (string != NULL ) {
1629
1627
opt = 0 ;
1630
1628
syntax = NULL ;
1631
- _php_mb_regex_init_options (string , string_len , & opt , & syntax , NULL );
1629
+ if (!_php_mb_regex_init_options (string , string_len , & opt , & syntax )) {
1630
+ RETURN_THROWS ();
1631
+ }
1632
1632
_php_mb_regex_set_options (opt , syntax , & prev_opt , & prev_syntax );
1633
1633
opt = prev_opt ;
1634
1634
syntax = prev_syntax ;
0 commit comments