@@ -102,6 +102,11 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length)
102102/* {{{ php_url_parse_ex2
103103 */
104104PHPAPI php_url * php_url_parse_ex2 (char const * str , size_t length , bool * has_port )
105+ {
106+ return php_url_parse_ex3 (str , length , false, has_port );
107+ }
108+
109+ PHPAPI php_url * php_url_parse_ex3 (char const * str , size_t length , bool strict , bool * has_port )
105110{
106111 char port_buf [6 ];
107112 php_url * ret = ecalloc (1 , sizeof (php_url ));
@@ -203,12 +208,16 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
203208 s += 2 ;
204209 }
205210 } else {
206- zend_value_error ("Invalid port (%s)" , port_buf );
211+ if (strict ) {
212+ zend_value_error ("Invalid port (%s)" , port_buf );
213+ }
207214 php_url_free (ret );
208215 return NULL ;
209216 }
210217 } else if (p == pp && pp == ue ) {
211- zend_value_error ("Invalid path (%s)" , str );
218+ if (strict ) {
219+ zend_value_error ("Invalid path (%s)" , str );
220+ }
212221 php_url_free (ret );
213222 return NULL ;
214223 } else if (s + 1 < ue && * s == '/' && * (s + 1 ) == '/' ) { /* relative-scheme URL */
@@ -256,7 +265,9 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
256265 if (!ret -> port ) {
257266 p ++ ;
258267 if (e - p > 5 ) { /* port cannot be longer then 5 characters */
259- zend_value_error ("Invalid port (%s)" , p );
268+ if (strict ) {
269+ zend_value_error ("Invalid port (%s)" , p );
270+ }
260271 php_url_free (ret );
261272 return NULL ;
262273 } else if (e - p > 0 ) {
@@ -269,7 +280,9 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
269280 * has_port = 1 ;
270281 ret -> port = (unsigned short )port ;
271282 } else {
272- zend_value_error ("Invalid port (%s)" , port_buf );
283+ if (strict ) {
284+ zend_value_error ("Invalid port (%s)" , port_buf );
285+ }
273286 php_url_free (ret );
274287 return NULL ;
275288 }
@@ -282,7 +295,9 @@ PHPAPI php_url *php_url_parse_ex2(char const *str, size_t length, bool *has_port
282295
283296 /* check if we have a valid host, if we don't reject the string as url */
284297 if ((p - s ) < 1 ) {
285- zend_value_error ("Invalid host (%s)" , s );
298+ if (strict ) {
299+ zend_value_error ("Invalid host (%s)" , s );
300+ }
286301 php_url_free (ret );
287302 return NULL ;
288303 }
@@ -340,18 +355,23 @@ PHP_FUNCTION(parse_url)
340355 php_url * resource ;
341356 zend_long key = -1 ;
342357 zval tmp ;
343- bool has_port ;
358+ bool has_port , strict = true ;
344359
345- ZEND_PARSE_PARAMETERS_START (1 , 2 )
360+ ZEND_PARSE_PARAMETERS_START (1 , 3 )
346361 Z_PARAM_STRING (str , str_len )
347362 Z_PARAM_OPTIONAL
348363 Z_PARAM_LONG (key )
364+ Z_PARAM_BOOL (strict )
349365 ZEND_PARSE_PARAMETERS_END ();
350366
351- resource = php_url_parse_ex2 (str , str_len , & has_port );
367+ resource = php_url_parse_ex3 (str , str_len , strict , & has_port );
352368 if (resource == NULL) {
353369 /* @todo Find a method to determine why php_url_parse_ex() failed */
354- RETURN_FALSE ;
370+ if (strict ) {
371+ RETURN_THROWS ();
372+ } else {
373+ RETURN_FALSE ;
374+ }
355375 }
356376
357377 if (key > -1 ) {
0 commit comments