php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #49007
Patch feature-49007.diff revision 2011-02-27 10:10 UTC by jthijssen at noxlogic dot nl
revision 2011-02-26 20:52 UTC by jthijssen at noxlogic dot nl

Patch feature-49007.diff for Strings related Bug #49007

Patch version 2011-02-27 10:10 UTC

Return to Bug #49007 | Download this patch
This patch renders other patches obsolete

Obsolete patches:

Patch Revisions: 2011-02-27 10:10 UTC | 2011-02-26 20:52 UTC

Developer: jthijssen@noxlogic.nl



  Index: ext/standard/string.c
  ===================================================================
 --- ext/standard/string.c	(revision 308566)
 --- ext/standard/string.c	(revision 308709)
  +++ ext/standard/string.c	(working copy)
  @@ -715,11 +715,12 @@
    * mode 3 : trim left and right
    * what indicates which chars are to be trimmed. NULL->default (' \t\n\r\v\0')


  +	php_trim(str, str_len, what, what_len, limit, return_value, mode TSRMLS_CC);
   }
   /* }}} */
   
 Index: ext/standard/php_string.h
 ===================================================================
 --- ext/standard/php_string.h	(revision 308566)
 +++ ext/standard/php_string.h	(working copy)
 @@ -132,7 +132,7 @@
  		int needle_len, char *str, int str_len, int *_new_length, int case_sensitivity, int *replace_count);
  PHPAPI char *php_str_to_str(char *haystack, int length, char *needle,
  		int needle_len, char *str, int str_len, int *_new_length);
 -PHPAPI char *php_trim(char *c, int len, char *what, int what_len, zval *return_value, int mode TSRMLS_DC);
 +PHPAPI char *php_trim(char *c, int len, char *what, int what_len, int limit, zval *return_value, int mode TSRMLS_DC);
  PHPAPI size_t php_strip_tags(char *rbuf, int len, int *state, char *allow, int allow_len);
  PHPAPI size_t php_strip_tags_ex(char *rbuf, int len, int *stateptr, char *allow, int allow_len, zend_bool allow_tag_spaces);
  PHPAPI int php_char_to_str_ex(char *str, uint len, char from, char *to, int to_len, zval *result, int case_sensitivity, int *replace_count);
 Index: ext/standard/tests/strings/trim1.phpt
 ===================================================================
 Binary files ext/standard/tests/strings/trim1.phpt	(revision 308566) and ext/standard/tests/strings/trim1.phpt	(working copy) differ
  Index: ext/standard/tests/strings/trim_basic.phpt
  ===================================================================
 --- ext/standard/tests/strings/trim_basic.phpt	(revision 308566)
 --- ext/standard/tests/strings/trim_basic.phpt	(revision 308709)
  +++ ext/standard/tests/strings/trim_basic.phpt	(working copy)
 @@ -3,7 +3,7 @@
  --FILE--
  <?php
  
 -/* Prototype  : string trim  ( string $str  [, string $charlist  ] )
 @@ -3,7 +3,7 @@
  --FILE--
  <?php
  
 -/* Prototype  : string trim  ( string $str  [, string $charlist  ] )
  +/* Prototype  : string trim  ( string $str  [, string $charlist [, int limit = -1 ] ] )
    * Description: Strip whitespace (or other characters) from the beginning and end of a string.
   * Source code: ext/standard/string.c
  */
 Index: ext/standard/tests/strings/trim_variation1.phpt
 ===================================================================
 --- ext/standard/tests/strings/trim_variation1.phpt	(revision 308709)
 +++ ext/standard/tests/strings/trim_variation1.phpt	(working copy)
 @@ -3,7 +3,7 @@
  --FILE--
  <?php
  
 -/* Prototype  : string trim  ( string $str  [, string $charlist  ] )
 +/* Prototype  : string trim  ( string $str  [, string $charlist [, int limit = -1 ] ] )
   * Description: Strip whitespace (or other characters) from the begining and end of a string.
   * Source code: ext/standard/string.c
  */
 Index: ext/standard/tests/strings/trim_variation2.phpt
 ===================================================================
 --- ext/standard/tests/strings/trim_variation2.phpt	(revision 308709)
 +++ ext/standard/tests/strings/trim_variation2.phpt	(working copy)
 @@ -3,7 +3,7 @@
  --FILE--
  <?php
  
 -/* Prototype  : string trim  ( string $str  [, string $charlist  ] )
 +/* Prototype  : string trim  ( string $str  [, string $charlist [, int limit = -1 ] ] )
   * Description: Strip whitespace (or other characters) from the begining and end of a string.
    * Source code: ext/standard/string.c
   */
  Index: ext/standard/tests/strings/trim_error.phpt
  ===================================================================
 --- ext/standard/tests/strings/trim_error.phpt	(revision 308566)
 --- ext/standard/tests/strings/trim_error.phpt	(revision 308709)
  +++ ext/standard/tests/strings/trim_error.phpt	(working copy)
  @@ -3,7 +3,7 @@
   --FILE--
  <?php
  <?php
   
  -/* Prototype  : string trim  ( string $str  [, string $charlist  ] )
  +/* Prototype  : string trim  ( string $str  [, string $charlist [, int limit = -1 ] ] )
    * Description: Strip whitespace (or other characters) from the begining and end of a string.


  +Warning: trim() expects at most 3 parameters, 4 given in %s on line %d
   NULL
   
   -- Test trim function with various invalid charlists --
 Index: ext/standard/tests/strings/trim_variation1.phpt
 ===================================================================
 --- ext/standard/tests/strings/trim_variation1.phpt	(revision 308566)
 +++ ext/standard/tests/strings/trim_variation1.phpt	(working copy)
 @@ -3,7 +3,7 @@
  --FILE--
  <?php
  
 -/* Prototype  : string trim  ( string $str  [, string $charlist  ] )
 +/* Prototype  : string trim  ( string $str  [, string $charlist [, int limit = -1 ] ] )
   * Description: Strip whitespace (or other characters) from the begining and end of a string.
   * Source code: ext/standard/string.c
  */
 Index: ext/standard/tests/strings/trim_variation2.phpt
 ===================================================================
 --- ext/standard/tests/strings/trim_variation2.phpt	(revision 308566)
 +++ ext/standard/tests/strings/trim_variation2.phpt	(working copy)
 @@ -3,7 +3,7 @@
  --FILE--
  <?php
 Index: ext/standard/http_fopen_wrapper.c
 ===================================================================
 --- ext/standard/http_fopen_wrapper.c	(revision 308709)
 +++ ext/standard/http_fopen_wrapper.c	(working copy)
 @@ -413,13 +413,13 @@
  			smart_str_0(&tmpstr);
  			/* Remove newlines and spaces from start and end. there's at least one extra \r\n at the end that needs to go. */
  			if (tmpstr.c) {
 -				tmp = php_trim(tmpstr.c, strlen(tmpstr.c), NULL, 0, NULL, 3 TSRMLS_CC);
 +				tmp = php_trim(tmpstr.c, strlen(tmpstr.c), NULL, 0, -1, NULL, 3 TSRMLS_CC);
  				smart_str_free(&tmpstr);
  			}
  		}
  		if (Z_TYPE_PP(tmpzval) == IS_STRING && Z_STRLEN_PP(tmpzval)) {
  			/* Remove newlines and spaces from start and end php_trim will estrndup() */
 -			tmp = php_trim(Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval), NULL, 0, NULL, 3 TSRMLS_CC);
 +			tmp = php_trim(Z_STRVAL_PP(tmpzval), Z_STRLEN_PP(tmpzval), NULL, 0, -1, NULL, 3 TSRMLS_CC);
  		}
  		if (tmp && strlen(tmp) > 0) {
  			char *s;
 @@ -449,7 +449,7 @@
  				}
  
  				efree(tmp_c);
 -				tmp_c = php_trim(tmp, strlen(tmp), NULL, 0, NULL, 3 TSRMLS_CC);
 +				tmp_c = php_trim(tmp, strlen(tmp), NULL, 0, -1, NULL, 3 TSRMLS_CC);
  				efree(tmp);
  				tmp = tmp_c;
  			}
 Index: ext/standard/mail.c
 ===================================================================
 --- ext/standard/mail.c	(revision 308709)
 +++ ext/standard/mail.c	(working copy)
 @@ -115,7 +115,7 @@
  	MAIL_ASCIIZ_CHECK(message, message_len);
  	if (headers) {
  		MAIL_ASCIIZ_CHECK(headers, headers_len);
 -		headers_trimmed = php_trim(headers, headers_len, NULL, 0, NULL, 2 TSRMLS_CC);
 +		headers_trimmed = php_trim(headers, headers_len, NULL, 0, -1, NULL, 2 TSRMLS_CC);
  	}
  	if (extra_cmd) {
  		MAIL_ASCIIZ_CHECK(extra_cmd, extra_cmd_len);
 Index: ext/standard/php_string.h
 ===================================================================
 --- ext/standard/php_string.h	(revision 308709)
 +++ ext/standard/php_string.h	(working copy)
 @@ -132,7 +132,7 @@
  		int needle_len, char *str, int str_len, int *_new_length, int case_sensitivity, int *replace_count);
  PHPAPI char *php_str_to_str(char *haystack, int length, char *needle,
  		int needle_len, char *str, int str_len, int *_new_length);
 -PHPAPI char *php_trim(char *c, int len, char *what, int what_len, zval *return_value, int mode TSRMLS_DC);
 +PHPAPI char *php_trim(char *c, int len, char *what, int what_len, int limit, zval *return_value, int mode TSRMLS_DC);
  PHPAPI size_t php_strip_tags(char *rbuf, int len, int *state, char *allow, int allow_len);
  PHPAPI size_t php_strip_tags_ex(char *rbuf, int len, int *stateptr, char *allow, int allow_len, zend_bool allow_tag_spaces);
  PHPAPI int php_char_to_str_ex(char *str, uint len, char from, char *to, int to_len, zval *result, int case_sensitivity, int *replace_count);
 Index: ext/curl/streams.c
 ===================================================================
 --- ext/curl/streams.c	(revision 308709)
 +++ ext/curl/streams.c	(working copy)
 @@ -353,10 +353,10 @@
  			} else if (Z_TYPE_PP(ctx_opt) == IS_STRING && Z_STRLEN_PP(ctx_opt)) {
  				char *p, *token, *trimmed, *copy_ctx_opt;
  
 -				copy_ctx_opt = php_trim(Z_STRVAL_PP(ctx_opt), Z_STRLEN_PP(ctx_opt), NULL, 0, NULL, 3 TSRMLS_CC);
 +				copy_ctx_opt = php_trim(Z_STRVAL_PP(ctx_opt), Z_STRLEN_PP(ctx_opt), NULL, 0, -1, NULL, 3 TSRMLS_CC);
  				p = php_strtok_r(copy_ctx_opt, "\r\n", &token);
  				while (p) {
 -					trimmed = php_trim(p, strlen(p), NULL, 0, NULL, 3 TSRMLS_CC);
 +					trimmed = php_trim(p, strlen(p), NULL, 0, -1, NULL, 3 TSRMLS_CC);
  					slist = curl_slist_append(slist, trimmed);
  					efree(trimmed);
  					p = php_strtok_r(NULL, "\r\n", &token);
 Index: ext/mbstring/mbstring.c
 ===================================================================
 --- ext/mbstring/mbstring.c	(revision 308709)
 +++ ext/mbstring/mbstring.c	(working copy)
 @@ -1363,7 +1363,7 @@
  		new_value = entry->orig_value;
  		new_value_length = entry->orig_value_length;
  	}
 -	php_trim(new_value, new_value_length, NULL, 0, &tmp, 3 TSRMLS_CC);
 +	php_trim(new_value, new_value_length, NULL, 0, -1, &tmp, 3 TSRMLS_CC);
   
 -/* Prototype  : string trim  ( string $str  [, string $charlist  ] )
 +/* Prototype  : string trim  ( string $str  [, string $charlist [, int limit = -1 ] ] )
   * Description: Strip whitespace (or other characters) from the begining and end of a string.
   * Source code: ext/standard/string.c
  */
 Index: ext/standard/tests/strings/trim_variation3.phpt
  	if (Z_STRLEN(tmp) > 0) {
  		if (!(re = _php_mb_compile_regex(Z_STRVAL(tmp) TSRMLS_CC))) {
 Index: ext/simplexml/simplexml.c
  ===================================================================
 --- ext/standard/tests/strings/trim_variation3.phpt	(revision 0)
 +++ ext/standard/tests/strings/trim_variation3.phpt	(revision 0)
 @@ -0,0 +1,46 @@
 +--TEST--
 +Test trim() function : usage variations - test limit argument
 +--FILE--
 +<?php
 +
 +/* Prototype  : string trim  ( string $str  [, string $charlist [, int limit = -1 ] ] )
 + * Description: Strip whitespace (or other characters) from the begining and end of a string.
 + * Source code: ext/standard/string.c
 +*/
 +
 +echo "*** Testing trim() function: with different limit arguments ***\n";
 +
 +var_dump (trim("  hello  ", " \n\r\t\v\0", 1));
 +var_dump (trim("  hello  ", " \n\r\t\v\0", 5));
 +var_dump (trim("  hello  ", " \n\r\t\v\0", 0));
 +var_dump (trim("  hello  ", " \n\r\t\v\0", -1));
 +
 +var_dump (ltrim("  hello  ", " \n\r\t\v\0", 1));
 +var_dump (ltrim("  hello  ", " \n\r\t\v\0", 5));
 +var_dump (ltrim("  hello  ", " \n\r\t\v\0", 0));
 +var_dump (ltrim("  hello  ", " \n\r\t\v\0", -1));
 +
 +var_dump (rtrim("  hello  ", " \n\r\t\v\0", 1));
 +var_dump (rtrim("  hello  ", " \n\r\t\v\0", 5));
 +var_dump (rtrim("  hello  ", " \n\r\t\v\0", 0));
 +var_dump (rtrim("  hello  ", " \n\r\t\v\0", -1));
 +
 +
 +
 +?>
 +===DONE===
 +--EXPECT--
 +*** Testing trim() function: with different limit arguments ***
 +string(7) " hello "
 +string(5) "hello"
 +string(9) "  hello  "
 +string(5) "hello"
 +string(8) " hello  "
 +string(7) "hello  "
 +string(9) "  hello  "
 +string(7) "hello  "
 +string(8) "  hello "
 +string(7) "  hello"
 +string(9) "  hello  "
 +string(7) "  hello"
 +===DONE===
 \ No newline at end of file
 --- ext/simplexml/simplexml.c	(revision 308709)
 +++ ext/simplexml/simplexml.c	(working copy)
 @@ -485,7 +485,7 @@
  			trim_zv = *member;
  			zval_copy_ctor(&trim_zv);
  			convert_to_string(&trim_zv);
 -			php_trim(Z_STRVAL(trim_zv), Z_STRLEN(trim_zv), NULL, 0, &tmp_zv, 3 TSRMLS_CC);
 +			php_trim(Z_STRVAL(trim_zv), Z_STRLEN(trim_zv), NULL, 0, -1, &tmp_zv, 3 TSRMLS_CC);
  			zval_dtor(&trim_zv);
  			member = &tmp_zv;
  		}
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Dec 06 07:01:25 2019 UTC