From 0baaf9fade6f4ef1b2da824cac76bb78ff798611 Mon Sep 17 00:00:00 2001 From: George Wang Date: Fri, 11 Jul 2014 14:31:59 -0400 Subject: [PATCH 1/5] Fixed a bug that cannot access custom request header stored in apache_request_headers() though array index. --- sapi/litespeed/lsapilib.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sapi/litespeed/lsapilib.c b/sapi/litespeed/lsapilib.c index 92c169f4f5a..786a3bd20b2 100644 --- a/sapi/litespeed/lsapilib.c +++ b/sapi/litespeed/lsapilib.c @@ -1945,6 +1945,7 @@ int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq, { pKey = pReq->m_pHttpHeader + pCur->nameOff; keyLen = pCur->nameLen; + *(pKey + keyLen ) = 0; pValue = pReq->m_pHttpHeader + pCur->valueOff; *(pValue + pCur->valueLen ) = 0; From 9f721967a329387bf73c0d5bebe9578ba772601e Mon Sep 17 00:00:00 2001 From: George Wang Date: Fri, 11 Jul 2014 14:31:59 -0400 Subject: [PATCH 2/5] Fixed a bug that cannot access custom request header stored in apache_request_headers() though array index. --- sapi/litespeed/lsapilib.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sapi/litespeed/lsapilib.c b/sapi/litespeed/lsapilib.c index 92c169f4f5a..786a3bd20b2 100644 --- a/sapi/litespeed/lsapilib.c +++ b/sapi/litespeed/lsapilib.c @@ -1945,6 +1945,7 @@ int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq, { pKey = pReq->m_pHttpHeader + pCur->nameOff; keyLen = pCur->nameLen; + *(pKey + keyLen ) = 0; pValue = pReq->m_pHttpHeader + pCur->valueOff; *(pValue + pCur->valueLen ) = 0; From 4fc0d46ae72de2b009357091b4e62eafd0f1e8a5 Mon Sep 17 00:00:00 2001 From: Tjerk Meesters Date: Wed, 2 Jul 2014 22:22:11 +0800 Subject: [PATCH 3/5] Fix for bug #34407 - ucwords and title case Added support for ranges like trim() has --- ext/standard/basic_functions.c | 3 ++- ext/standard/string.c | 11 +++++--- ext/standard/tests/strings/ucwords_error.phpt | 6 ++--- .../tests/strings/ucwords_variation5.phpt | 25 +++++++++++++++++++ 4 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 ext/standard/tests/strings/ucwords_variation5.phpt diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 4d4354d4ad6..9a9df3094be 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -2309,8 +2309,9 @@ ZEND_BEGIN_ARG_INFO(arginfo_lcfirst, 0) ZEND_ARG_INFO(0, str) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO(arginfo_ucwords, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_ucwords, 0, 0, 1) ZEND_ARG_INFO(0, str) + ZEND_ARG_INFO(0, delimiters) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_strtr, 0, 0, 2) diff --git a/ext/standard/string.c b/ext/standard/string.c index 22b1957f1e0..7bc21598712 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -2742,11 +2742,12 @@ PHP_FUNCTION(lcfirst) Uppercase the first character of every word in a string */ PHP_FUNCTION(ucwords) { - char *str; + char *str, *delims = " \t\r\n\f\v"; register char *r, *r_end; - int str_len; + int str_len, delims_len = 6; + char mask[256]; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &str, &str_len, &delims, &delims_len) == FAILURE) { return; } @@ -2754,12 +2755,14 @@ PHP_FUNCTION(ucwords) RETURN_EMPTY_STRING(); } + php_charmask((unsigned char *)delims, delims_len, mask TSRMLS_CC); + ZVAL_STRINGL(return_value, str, str_len, 1); r = Z_STRVAL_P(return_value); *r = toupper((unsigned char) *r); for (r_end = r + Z_STRLEN_P(return_value) - 1; r < r_end; ) { - if (isspace((int) *(unsigned char *)r++)) { + if (mask[(unsigned char)*r++]) { *r = toupper((unsigned char) *r); } } diff --git a/ext/standard/tests/strings/ucwords_error.phpt b/ext/standard/tests/strings/ucwords_error.phpt index d79e569cc7b..a01c688c4a5 100644 --- a/ext/standard/tests/strings/ucwords_error.phpt +++ b/ext/standard/tests/strings/ucwords_error.phpt @@ -18,7 +18,7 @@ echo "\n-- Testing ucwords() function with more than expected no. of arguments - $str = 'string_val'; $extra_arg = 10; -var_dump( ucwords($str, $extra_arg) ); +var_dump( ucwords($str, $extra_arg, $extra_arg) ); // check if there were any changes made to $str var_dump($str); @@ -30,12 +30,12 @@ echo "Done\n"; -- Testing ucwords() function with Zero arguments -- -Warning: ucwords() expects exactly 1 parameter, 0 given in %s on line %d +Warning: ucwords() expects at least 1 parameter, 0 given in %s on line %d NULL -- Testing ucwords() function with more than expected no. of arguments -- -Warning: ucwords() expects exactly 1 parameter, 2 given in %s on line %d +Warning: ucwords() expects at most 2 parameters, 3 given in %s on line %d NULL string(10) "string_val" Done diff --git a/ext/standard/tests/strings/ucwords_variation5.phpt b/ext/standard/tests/strings/ucwords_variation5.phpt new file mode 100644 index 00000000000..985df47c4ab --- /dev/null +++ b/ext/standard/tests/strings/ucwords_variation5.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test ucwords() function : usage variations - custom delimiters +--FILE-- + +--EXPECTF-- +*** Testing ucwords() : usage variations *** +string(%d) "Testing-Dashed-Words" +string(%d) "Test(Braced)Words" +string(%d) "Testing empty delimiters" +string(%d) "TeSting raNgeS" +Done From f25ff02b54ac2dc161df91569ce0a396d59e5a4d Mon Sep 17 00:00:00 2001 From: Tjerk Meesters Date: Sat, 12 Jul 2014 11:07:06 +0800 Subject: [PATCH 4/5] Updated NEWS for 34407 --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index 20d4f30b5f1..fd58bd62a32 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ PHP NEWS . Fixed bug #67151 (strtr with empty array crashes). (Nikita) . Fixed bug #67407 (Windows 8.1/Server 2012 R2 reported as Windows 8/Server 2012). (Christian Wenz) + . Implemented FR #34407 (ucwords and Title Case). (Tjerk) - CLI server: . Implemented FR #67429 (CLI server is missing some new HTTP response codes). From 377750cd8f9618498d05c0ac7a79b05a5c6794d4 Mon Sep 17 00:00:00 2001 From: Tjerk Meesters Date: Sat, 12 Jul 2014 11:09:35 +0800 Subject: [PATCH 5/5] Updated NEWS for 34407 --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index bd76438534e..7ab2d29493e 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,7 @@ PHP NEWS . Fixed bug #67151 (strtr with empty array crashes). (Nikita) . Fixed bug #67407 (Windows 8.1/Server 2012 R2 reported as Windows 8/Server 2012). (Christian Wenz) + . Implemented FR #34407 (ucwords and Title Case). (Tjerk) - CLI server: . Implemented FR #67429 (CLI server is missing some new HTTP response codes).