summaryrefslogtreecommitdiff
path: root/ext/standard
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2012-08-20 08:34:35 +0200
committerOndřej Surý <ondrej@sury.org>2012-08-20 08:34:35 +0200
commit45c0aa447e02c80bd21a23245574231a110cf5a1 (patch)
treeb801de455f164afbf40fbbc995ab9751163eee84 /ext/standard
parent3365f28adf90110ca7475df889720fc244820f4b (diff)
downloadphp-45c0aa447e02c80bd21a23245574231a110cf5a1.tar.gz
Imported Upstream version 5.4.6upstream/5.4.6
Diffstat (limited to 'ext/standard')
-rw-r--r--ext/standard/basic_functions.c2
-rw-r--r--ext/standard/file.c1
-rw-r--r--ext/standard/incomplete_class.c2
-rw-r--r--ext/standard/mail.c55
-rw-r--r--ext/standard/math.c24
-rw-r--r--ext/standard/string.c15
-rw-r--r--ext/standard/tests/file/realpath_cache.phpt2
-rw-r--r--ext/standard/tests/general_functions/bug27678.phpt4
-rw-r--r--ext/standard/tests/general_functions/debug_zval_dump_o.phpt2
-rw-r--r--ext/standard/tests/general_functions/uniqid_basic.phpt145
-rw-r--r--ext/standard/tests/math/bug62112.phptbin0 -> 143 bytes
-rw-r--r--ext/standard/tests/streams/bug61115-1.phpt6
-rw-r--r--ext/standard/tests/strings/http_build_query_variation1.phpt30
-rw-r--r--ext/standard/tests/strings/http_build_query_variation2.phpt39
-rw-r--r--ext/standard/tests/strings/http_build_query_variation3.phpt27
-rw-r--r--ext/standard/tests/zend_logo_guid.phpt2
16 files changed, 258 insertions, 98 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index a5637db50..e6de34e5f 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -3719,8 +3719,6 @@ PHP_RINIT_FUNCTION(basic) /* {{{ */
/* Default to global filters only */
FG(stream_filters) = NULL;
- FG(wrapper_errors) = NULL;
-
return SUCCESS;
}
/* }}} */
diff --git a/ext/standard/file.c b/ext/standard/file.c
index 7d01d3135..cce0143ff 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -161,6 +161,7 @@ static void file_globals_ctor(php_file_globals *file_globals_p TSRMLS_DC)
FG(pclose_ret) = 0;
FG(user_stream_current_filename) = NULL;
FG(def_chunk_size) = PHP_SOCK_CHUNK_SIZE;
+ FG(wrapper_errors) = NULL;
}
static void file_globals_dtor(php_file_globals *file_globals_p TSRMLS_DC)
diff --git a/ext/standard/incomplete_class.c b/ext/standard/incomplete_class.c
index 0ca2f04cf..f6d3750e2 100644
--- a/ext/standard/incomplete_class.c
+++ b/ext/standard/incomplete_class.c
@@ -109,6 +109,8 @@ static zend_object_value php_create_incomplete_object(zend_class_entry *class_ty
value = zend_objects_new(&object, class_type TSRMLS_CC);
value.handlers = &php_incomplete_object_handlers;
+ object_properties_init(object, class_type);
+
return value;
}
diff --git a/ext/standard/mail.c b/ext/standard/mail.c
index 36568c508..364f7fc39 100644
--- a/ext/standard/mail.c
+++ b/ext/standard/mail.c
@@ -39,6 +39,7 @@
#endif
#endif
+#include "php_syslog.h"
#include "php_mail.h"
#include "php_ini.h"
#include "php_string.h"
@@ -189,6 +190,37 @@ PHP_FUNCTION(mail)
}
/* }}} */
+
+void php_mail_log_crlf_to_spaces(char *message) {
+ /* Find all instances of carriage returns or line feeds and
+ * replace them with spaces. Thus, a log line is always one line
+ * long
+ */
+ char *p = message;
+ while ((p = strpbrk(p, "\r\n"))) {
+ *p = ' ';
+ }
+}
+
+void php_mail_log_to_syslog(char *message) {
+ /* Write 'message' to syslog. */
+#ifdef HAVE_SYSLOG_H
+ php_syslog(LOG_NOTICE, "%s", message);
+#endif
+}
+
+
+void php_mail_log_to_file(char *filename, char *message, size_t message_size TSRMLS_DC) {
+ /* Write 'message' to the given file. */
+ uint flags = IGNORE_URL_WIN | REPORT_ERRORS | STREAM_DISABLE_OPEN_BASEDIR;
+ php_stream *stream = php_stream_open_wrapper(filename, "a", flags, NULL);
+ if (stream) {
+ php_stream_write(stream, message, message_size);
+ php_stream_close(stream);
+ }
+}
+
+
/* {{{ php_mail
*/
PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd TSRMLS_DC)
@@ -216,19 +248,22 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
if (mail_log && *mail_log) {
char *tmp;
int l = spprintf(&tmp, 0, "mail() on [%s:%d]: To: %s -- Headers: %s\n", zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C), to, hdr ? hdr : "");
- php_stream *stream = php_stream_open_wrapper(mail_log, "a", IGNORE_URL_WIN | REPORT_ERRORS | STREAM_DISABLE_OPEN_BASEDIR, NULL);
- if (hdr) { /* find all \r\n instances and replace them with spaces, so a log line is always one line long */
- char *p = tmp;
- while ((p = strpbrk(p, "\r\n"))) {
- *p = ' ';
- }
- tmp[l - 1] = '\n';
+ if (hdr) {
+ php_mail_log_crlf_to_spaces(tmp);
}
- if (stream) {
- php_stream_write(stream, tmp, l);
- php_stream_close(stream);
+
+ if (!strcmp(mail_log, "syslog")) {
+ /* Drop the final space when logging to syslog. */
+ tmp[l - 1] = 0;
+ php_mail_log_to_syslog(tmp);
+ }
+ else {
+ /* Convert the final space to a newline when logging to file. */
+ tmp[l - 1] = '\n';
+ php_mail_log_to_file(mail_log, tmp, l TSRMLS_CC);
}
+
efree(tmp);
}
if (PG(mail_x_header)) {
diff --git a/ext/standard/math.c b/ext/standard/math.c
index 65187f6fa..6e934a385 100644
--- a/ext/standard/math.c
+++ b/ext/standard/math.c
@@ -1097,7 +1097,9 @@ PHPAPI char *_php_math_number_format(double d, int dec, char dec_point, char tho
return _php_math_number_format_ex(d, dec, &dec_point, 1, &thousand_sep, 1);
}
-PHPAPI char *_php_math_number_format_ex(double d, int dec, char *dec_point, size_t dec_point_len, char *thousand_sep, size_t thousand_sep_len)
+static char *_php_math_number_format_ex_len(double d, int dec, char *dec_point,
+ size_t dec_point_len, char *thousand_sep, size_t thousand_sep_len,
+ int *result_len)
{
char *tmpbuf = NULL, *resbuf;
char *s, *t; /* source, target */
@@ -1118,6 +1120,10 @@ PHPAPI char *_php_math_number_format_ex(double d, int dec, char *dec_point, size
tmplen = spprintf(&tmpbuf, 0, "%.*F", dec, d);
if (tmpbuf == NULL || !isdigit((int)tmpbuf[0])) {
+ if (result_len) {
+ *result_len = tmplen;
+ }
+
return tmpbuf;
}
@@ -1205,8 +1211,19 @@ PHPAPI char *_php_math_number_format_ex(double d, int dec, char *dec_point, size
efree(tmpbuf);
+ if (result_len) {
+ *result_len = reslen;
+ }
+
return resbuf;
}
+
+PHPAPI char *_php_math_number_format_ex(double d, int dec, char *dec_point,
+ size_t dec_point_len, char *thousand_sep, size_t thousand_sep_len)
+{
+ return _php_math_number_format_ex_len(d, dec, dec_point, dec_point_len,
+ thousand_sep, thousand_sep_len, NULL);
+}
/* }}} */
/* {{{ proto string number_format(float number [, int num_decimal_places [, string dec_seperator, string thousands_seperator]])
@@ -1241,7 +1258,10 @@ PHP_FUNCTION(number_format)
thousand_sep_len = 1;
}
- RETURN_STRING(_php_math_number_format_ex(num, dec, dec_point, dec_point_len, thousand_sep, thousand_sep_len), 0);
+ Z_TYPE_P(return_value) = IS_STRING;
+ Z_STRVAL_P(return_value) = _php_math_number_format_ex_len(num, dec,
+ dec_point, dec_point_len, thousand_sep, thousand_sep_len,
+ &Z_STRLEN_P(return_value));
break;
default:
WRONG_PARAM_COUNT;
diff --git a/ext/standard/string.c b/ext/standard/string.c
index 5c33232f7..9a64376c2 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -131,8 +131,8 @@ static char *php_bin2hex(const unsigned char *old, const size_t oldlen, size_t *
register unsigned char *result = NULL;
size_t i, j;
- result = (unsigned char *) safe_emalloc(oldlen * 2, sizeof(char), 1);
-
+ result = (unsigned char *) safe_emalloc(oldlen, 2 * sizeof(char), 1);
+
for (i = j = 0; i < oldlen; i++) {
result[j++] = hexconvtab[old[i] >> 4];
result[j++] = hexconvtab[old[i] & 15];
@@ -4029,13 +4029,12 @@ PHP_FUNCTION(nl2br)
RETURN_STRINGL(str, str_len, 1);
}
- if (is_xhtml) {
- new_length = str_len + repl_cnt * (sizeof("<br />") - 1);
- } else {
- new_length = str_len + repl_cnt * (sizeof("<br>") - 1);
- }
+ {
+ size_t repl_len = is_xhtml ? (sizeof("<br />") - 1) : (sizeof("<br>") - 1);
- tmp = target = emalloc(new_length + 1);
+ new_length = str_len + repl_cnt * repl_len;
+ tmp = target = safe_emalloc(repl_cnt, repl_len, str_len + 1);
+ }
while (str < end) {
switch (*str) {
diff --git a/ext/standard/tests/file/realpath_cache.phpt b/ext/standard/tests/file/realpath_cache.phpt
index 92d6fc5b2..2dac21ec4 100644
--- a/ext/standard/tests/file/realpath_cache.phpt
+++ b/ext/standard/tests/file/realpath_cache.phpt
@@ -19,7 +19,7 @@ echo "Done\n";
int(%d)
array(4) {
["key"]=>
- %s(%d)
+ %s(%s)
["is_dir"]=>
bool(true)
["realpath"]=>
diff --git a/ext/standard/tests/general_functions/bug27678.phpt b/ext/standard/tests/general_functions/bug27678.phpt
index 5db5890a1..6f95509e1 100644
--- a/ext/standard/tests/general_functions/bug27678.phpt
+++ b/ext/standard/tests/general_functions/bug27678.phpt
@@ -6,9 +6,11 @@ Bug #27678 (number_format() crashes with large numbers)
number_format(1e80, 0, '', ' ');
number_format(1e300, 0, '', ' ');
number_format(1e320, 0, '', ' ');
-number_format(1e1000, 0, '', ' ');
+$num = number_format(1e1000, 0, '', ' ');
+var_dump(strlen($num) == 3); // $num == 'inf'
echo "Done\n";
?>
--EXPECT--
+bool(true)
Done
diff --git a/ext/standard/tests/general_functions/debug_zval_dump_o.phpt b/ext/standard/tests/general_functions/debug_zval_dump_o.phpt
index dd4b5142a..78f0f0300 100644
--- a/ext/standard/tests/general_functions/debug_zval_dump_o.phpt
+++ b/ext/standard/tests/general_functions/debug_zval_dump_o.phpt
@@ -1,5 +1,7 @@
--TEST--
Test debug_zval_dump() function : working on objects
+--SKIPIF--
+<?php if (PHP_ZTS) { print "skip only for no-zts build"; }
--FILE--
<?php
/* Prototype: void debug_zval_dump ( mixed $variable );
diff --git a/ext/standard/tests/general_functions/uniqid_basic.phpt b/ext/standard/tests/general_functions/uniqid_basic.phpt
index 9a9c57332..2da832b8e 100644
--- a/ext/standard/tests/general_functions/uniqid_basic.phpt
+++ b/ext/standard/tests/general_functions/uniqid_basic.phpt
@@ -1,73 +1,72 @@
---TEST--
-Test uniqid() function : basic functionality
---FILE--
-<?php
-/* Prototype : string uniqid ([ string $prefix= "" [, bool $more_entropy= false ]] )
- * Description: Gets a prefixed unique identifier based on the current time in microseconds.
- * Source code: ext/standard/uniqid.c
-*/
-echo "*** Testing uniqid() : basic functionality ***\n";
-
-echo "\nuniqid() without a prefix\n";
-var_dump(uniqid());
-var_dump(uniqid(null, true));
-var_dump(uniqid(null, false));
-echo "\n\n";
-
-echo "uniqid() with a prefix\n";
-
-// Use a fixed prefix so we can ensure length of o/p id is fixed
-$prefix = array (
- 99999,
- "99999",
- 10.5e2,
- null,
- true,
- false
- );
-
-for ($i = 0; $i < count($prefix); $i++) {
- var_dump(uniqid($prefix[$i]));
- var_dump(uniqid($prefix[$i], true));
- var_dump(uniqid($prefix[$i], false));
- echo "\n";
-}
-
-?>
-===DONE===
---EXPECTF--
-*** Testing uniqid() : basic functionality ***
-
-uniqid() without a prefix
-string(13) "%s"
-string(23) "%s.%s"
-string(13) "%s"
-
-
-uniqid() with a prefix
-string(18) "99999%s"
-string(28) "99999%s.%s"
-string(18) "99999%s"
-
-string(18) "999994%s"
-string(28) "999994%s.%s"
-string(18) "999994%s"
-
-string(17) "1050%s"
-string(27) "1050%s.%s"
-string(17) "1050%s"
-
-string(13) "%s"
-string(23) "%s.%s"
-string(13) "%s"
-
-string(14) "1%s"
-string(24) "1%s.%s"
-string(14) "1%s"
-
-string(13) "%s"
-string(23) "%s.%s"
-string(13) "%s"
-
-===DONE===
- \ No newline at end of file
+--TEST--
+Test uniqid() function : basic functionality
+--FILE--
+<?php
+/* Prototype : string uniqid ([ string $prefix= "" [, bool $more_entropy= false ]] )
+ * Description: Gets a prefixed unique identifier based on the current time in microseconds.
+ * Source code: ext/standard/uniqid.c
+*/
+echo "*** Testing uniqid() : basic functionality ***\n";
+
+echo "\nuniqid() without a prefix\n";
+var_dump(uniqid());
+var_dump(uniqid(null, true));
+var_dump(uniqid(null, false));
+echo "\n\n";
+
+echo "uniqid() with a prefix\n";
+
+// Use a fixed prefix so we can ensure length of o/p id is fixed
+$prefix = array (
+ 99999,
+ "99999",
+ 10.5e2,
+ null,
+ true,
+ false
+ );
+
+for ($i = 0; $i < count($prefix); $i++) {
+ var_dump(uniqid($prefix[$i]));
+ var_dump(uniqid($prefix[$i], true));
+ var_dump(uniqid($prefix[$i], false));
+ echo "\n";
+}
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing uniqid() : basic functionality ***
+
+uniqid() without a prefix
+string(13) "%s"
+string(23) "%s.%s"
+string(13) "%s"
+
+
+uniqid() with a prefix
+string(18) "99999%s"
+string(28) "99999%s.%s"
+string(18) "99999%s"
+
+string(18) "99999%s"
+string(28) "99999%s.%s"
+string(18) "99999%s"
+
+string(17) "1050%s"
+string(27) "1050%s.%s"
+string(17) "1050%s"
+
+string(13) "%s"
+string(23) "%s.%s"
+string(13) "%s"
+
+string(14) "1%s"
+string(24) "1%s.%s"
+string(14) "1%s"
+
+string(13) "%s"
+string(23) "%s.%s"
+string(13) "%s"
+
+===DONE===
diff --git a/ext/standard/tests/math/bug62112.phpt b/ext/standard/tests/math/bug62112.phpt
new file mode 100644
index 000000000..01de35a9c
--- /dev/null
+++ b/ext/standard/tests/math/bug62112.phpt
Binary files differ
diff --git a/ext/standard/tests/streams/bug61115-1.phpt b/ext/standard/tests/streams/bug61115-1.phpt
index 89374e735..99e2f7929 100644
--- a/ext/standard/tests/streams/bug61115-1.phpt
+++ b/ext/standard/tests/streams/bug61115-1.phpt
@@ -1,5 +1,11 @@
--TEST--
Bug #61115: Stream related segfault on fatal error in php_stream_context_del_link - variation 1
+--SKIPIF--
+<?php
+if (getenv("USE_ZEND_ALLOC") === "0") {
+ die("skip Zend MM disabled");
+}
+?>
--FILE--
<?php
diff --git a/ext/standard/tests/strings/http_build_query_variation1.phpt b/ext/standard/tests/strings/http_build_query_variation1.phpt
new file mode 100644
index 000000000..56d81c9fd
--- /dev/null
+++ b/ext/standard/tests/strings/http_build_query_variation1.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Test http_build_query() function: usage variations - first arguments as object
+--CREDITS--
+Adam Gegotek <adam [dot] gegotek [at] gmail [dot] com>
+--FILE--
+<?php
+/* Prototype : string http_build_query ( mixed $query_data [, string $numeric_prefix [, string $arg_separator [, int $enc_type = PHP_QUERY_RFC1738 ]]] )
+ * Description: Generates a URL-encoded query string from the associative (or indexed) array provided.
+ * Source code: ext/standard/http.c
+*/
+
+class UrlBuilder
+{
+ public $name = 'homepage';
+ public $page = 1;
+ protected $sort = 'desc,name';
+ private $access = 'admin';
+}
+
+$obj = new stdClass;
+$obj->name = 'homepage';
+$obj->page = 1;
+$obj->sort = 'desc,name';
+
+echo http_build_query($obj) . PHP_EOL;
+echo http_build_query(new UrlBuilder());
+?>
+--EXPECTF--
+name=homepage&page=1&sort=desc%2Cname
+name=homepage&page=1
diff --git a/ext/standard/tests/strings/http_build_query_variation2.phpt b/ext/standard/tests/strings/http_build_query_variation2.phpt
new file mode 100644
index 000000000..ca1d8f459
--- /dev/null
+++ b/ext/standard/tests/strings/http_build_query_variation2.phpt
@@ -0,0 +1,39 @@
+--TEST--
+Test http_build_query() function: usage variations - first arguments as multidimensional array and second argument present/not present
+--CREDITS--
+Adam Gegotek <adam [dot] gegotek [at] gmail [dot] com>
+--FILE--
+<?php
+/* Prototype : string http_build_query ( mixed $query_data [, string $numeric_prefix [, string $arg_separator [, int $enc_type = PHP_QUERY_RFC1738 ]]] )
+ * Description: Generates a URL-encoded query string from the associative (or indexed) array provided.
+ * Source code: ext/standard/http.c
+*/
+
+$mDimensional = array(
+ 20,
+ 5 => 13,
+ "9" => array(
+ 1 => "val1",
+ 3 => "val2",
+ "string" => "string"
+ ),
+ "name" => "homepage",
+ "page" => 10,
+ "sort" => array(
+ "desc",
+ "admin" => array(
+ "admin1",
+ "admin2" => array(
+ "who" => "admin2",
+ 2 => "test"
+ )
+ )
+ )
+);
+
+echo http_build_query($mDimensional) . PHP_EOL;
+echo http_build_query($mDimensional, 'prefix_');
+?>
+--EXPECTF--
+0=20&5=13&9%5B1%5D=val1&9%5B3%5D=val2&9%5Bstring%5D=string&name=homepage&page=10&sort%5B0%5D=desc&sort%5Badmin%5D%5B0%5D=admin1&sort%5Badmin%5D%5Badmin2%5D%5Bwho%5D=admin2&sort%5Badmin%5D%5Badmin2%5D%5B2%5D=test
+prefix_0=20&prefix_5=13&prefix_9%5B1%5D=val1&prefix_9%5B3%5D=val2&prefix_9%5Bstring%5D=string&name=homepage&page=10&sort%5B0%5D=desc&sort%5Badmin%5D%5B0%5D=admin1&sort%5Badmin%5D%5Badmin2%5D%5Bwho%5D=admin2&sort%5Badmin%5D%5Badmin2%5D%5B2%5D=test
diff --git a/ext/standard/tests/strings/http_build_query_variation3.phpt b/ext/standard/tests/strings/http_build_query_variation3.phpt
new file mode 100644
index 000000000..107120e08
--- /dev/null
+++ b/ext/standard/tests/strings/http_build_query_variation3.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Test http_build_query() function: usage variations - testing four parameter added in PHP 5.4.0
+--CREDITS--
+Adam Gegotek <adam [dot] gegotek [at] gmail [dot] com>
+--SKIPIF--
+<?php
+ if (version_compare(PHP_VERSION, '5.4.0', '<')) die("skip this test if PHP_VERSION is less than 5.4.0");
+?>
+--FILE--
+<?php
+/* Prototype : string http_build_query ( mixed $query_data [, string $numeric_prefix [, string $arg_separator [, int $enc_type = PHP_QUERY_RFC1738 ]]] )
+ * Description: Generates a URL-encoded query string from the associative (or indexed) array provided.
+ * Source code: ext/standard/http.c
+*/
+
+$oDimensional = array(
+ "name" => "main page",
+ "sort" => "desc,admin",
+ "equation" => "10 + 10 - 5"
+);
+
+echo http_build_query($oDimensional, '', ini_get('arg_separator.output'), PHP_QUERY_RFC1738) . PHP_EOL;
+echo http_build_query($oDimensional, '', ini_get('arg_separator.output'), PHP_QUERY_RFC3986);
+?>
+--EXPECTF--
+name=main+page&sort=desc%2Cadmin&equation=10+%2B+10+-+5
+name=main%20page&sort=desc%2Cadmin&equation=10%20%2B%2010%20-%205
diff --git a/ext/standard/tests/zend_logo_guid.phpt b/ext/standard/tests/zend_logo_guid.phpt
index d26ed45e9..44e213b25 100644
--- a/ext/standard/tests/zend_logo_guid.phpt
+++ b/ext/standard/tests/zend_logo_guid.phpt
@@ -1,5 +1,5 @@
--TEST--
-Checking the zend_logo_guid() functio
+Checking the zend_logo_guid() function
--CREDITS--
Sebastian Schürmann
sschuermann@chip.de