summaryrefslogtreecommitdiff
path: root/ext/pcre
diff options
context:
space:
mode:
authorMark A. Hershberger <mah@debian.(none)>2009-03-25 00:34:59 -0400
committerMark A. Hershberger <mah@debian.(none)>2009-03-25 00:34:59 -0400
commitce7edc9b3c7370f32fec0bc7a8ec3e29ed9a5f61 (patch)
treeacdb9a8816483652a9db1a47db71df5df43707c5 /ext/pcre
parent10f5b47dc7c1cf2b9a00991629f43652710322d3 (diff)
downloadphp-ce7edc9b3c7370f32fec0bc7a8ec3e29ed9a5f61.tar.gz
Imported Upstream version 5.1.1upstream/5.1.1
Diffstat (limited to 'ext/pcre')
-rw-r--r--ext/pcre/config.w322
-rw-r--r--ext/pcre/config0.m4 (renamed from ext/pcre/config.m4)5
-rw-r--r--ext/pcre/php_pcre.c65
-rw-r--r--ext/pcre/php_pcre.h6
-rwxr-xr-xext/pcre/tests/bug34790.phpt23
-rw-r--r--ext/pcre/tests/pcre_count.phpt40
6 files changed, 112 insertions, 29 deletions
diff --git a/ext/pcre/config.w32 b/ext/pcre/config.w32
index 69badd0c0..2da2a3f31 100644
--- a/ext/pcre/config.w32
+++ b/ext/pcre/config.w32
@@ -1,4 +1,4 @@
-// $Id: config.w32,v 1.3.2.2 2005/08/25 18:36:45 edink Exp $
+// $Id: config.w32,v 1.4.2.1 2005/08/09 06:25:24 sebastian Exp $
// vim:ft=javascript
ARG_WITH("pcre-regex", "Perl Compatible Regular Expressions", "yes");
diff --git a/ext/pcre/config.m4 b/ext/pcre/config0.m4
index 7a4a8ff3b..c03cd4e7d 100644
--- a/ext/pcre/config.m4
+++ b/ext/pcre/config0.m4
@@ -1,5 +1,5 @@
dnl
-dnl $Id: config.m4,v 1.32.2.2 2005/08/22 16:55:56 andrei Exp $
+dnl $Id: config0.m4,v 1.36.2.1 2005/11/16 22:14:32 sniper Exp $
dnl
dnl By default we'll compile and link against the bundled PCRE library
@@ -15,6 +15,7 @@ if test "$PHP_PCRE_REGEX" != "no"; then
if test "$PHP_PCRE_REGEX" = "yes"; then
PHP_NEW_EXTENSION(pcre, pcrelib/pcre_chartables.c pcrelib/pcre_compile.c pcrelib/pcre_config.c pcrelib/pcre_dfa_exec.c pcrelib/pcre_exec.c pcrelib/pcre_fullinfo.c pcrelib/pcre_get.c pcrelib/pcre_globals.c pcrelib/pcre_info.c pcrelib/pcre_maketables.c pcrelib/pcre_ord2utf8.c pcrelib/pcre_printint.c pcrelib/pcre_refcount.c pcrelib/pcre_study.c pcrelib/pcre_tables.c pcrelib/pcre_try_flipped.c pcrelib/pcre_ucp_findchar.c pcrelib/pcre_valid_utf8.c pcrelib/pcre_version.c pcrelib/pcre_xclass.c php_pcre.c, $ext_shared,,-DEXPORT= -DNEWLINE=10 -DSUPPORT_UTF8 -DSUPPORT_UCP -DLINK_SIZE=2 -DPOSIX_MALLOC_THRESHOLD=10 -DMATCH_LIMIT=10000000 -I@ext_srcdir@/pcrelib)
PHP_ADD_BUILD_DIR($ext_builddir/pcrelib)
+ PHP_INSTALL_HEADERS([ext/pcre], [php_pcre.h pcrelib/])
AC_DEFINE(HAVE_BUNDLED_PCRE, 1, [ ])
else
for i in $PHP_PCRE_REGEX $PHP_PCRE_REGEX/include $PHP_PCRE_REGEX/include/pcre; do
@@ -25,7 +26,7 @@ if test "$PHP_PCRE_REGEX" != "no"; then
AC_MSG_ERROR([Could not find pcre.h in $PHP_PCRE_REGEX])
fi
- for j in $PHP_PCRE_REGEX $PHP_PCRE_REGEX/lib; do
+ for j in $PHP_PCRE_REGEX $PHP_PCRE_REGEX/$PHP_LIBDIR; do
test -f $j/libpcre.a -o -f $j/libpcre.$SHLIB_SUFFIX_NAME && PCRE_LIBDIR=$j
done
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index 16226a3cb..d5b1feaf1 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_pcre.c,v 1.157.2.5 2005/05/31 12:55:33 sniper Exp $ */
+/* $Id: php_pcre.c,v 1.168.2.3 2005/10/28 08:30:41 dmitry Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -100,7 +100,9 @@ static PHP_MINIT_FUNCTION(pcre)
/* {{{ PHP_MSHUTDOWN_FUNCTION(pcre) */
static PHP_MSHUTDOWN_FUNCTION(pcre)
{
-#ifndef ZTS
+#ifdef ZTS
+ ts_free_id(pcre_globals_id);
+#else
php_pcre_shutdown_globals(&pcre_globals TSRMLS_CC);
#endif
@@ -545,7 +547,7 @@ static void php_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global)
*/
if (count < num_subpats) {
for (; i < num_subpats; i++) {
- add_next_index_string(match_sets[i], empty_string, 1);
+ add_next_index_string(match_sets[i], "", 1);
}
}
} else {
@@ -620,6 +622,7 @@ static void php_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global)
if (subpat_names[i]) {
zend_hash_update(Z_ARRVAL_P(subpats), subpat_names[i],
strlen(subpat_names[i])+1, &match_sets[i], sizeof(zval *), NULL);
+ ZVAL_ADDREF(match_sets[i]);
}
zend_hash_next_index_insert(Z_ARRVAL_P(subpats), &match_sets[i], sizeof(zval *), NULL);
}
@@ -768,7 +771,7 @@ static int preg_do_eval(char *eval_str, int eval_str_len, char *subject,
esc_match_len = 0;
}
} else {
- esc_match = empty_string;
+ esc_match = "";
esc_match_len = 0;
match_len = 0;
}
@@ -792,7 +795,7 @@ static int preg_do_eval(char *eval_str, int eval_str_len, char *subject,
/* Run the code */
if (zend_eval_string(code.c, &retval, compiled_string_description TSRMLS_CC) == FAILURE) {
efree(compiled_string_description);
- php_error_docref(NULL TSRMLS_CC,E_ERROR, "Failed evaluating code:\n%s", code.c);
+ php_error_docref(NULL TSRMLS_CC,E_ERROR, "Failed evaluating code: %s%s", PHP_EOL, code.c);
/* zend_error() does not return in this case */
}
efree(compiled_string_description);
@@ -815,7 +818,7 @@ static int preg_do_eval(char *eval_str, int eval_str_len, char *subject,
PHPAPI char *php_pcre_replace(char *regex, int regex_len,
char *subject, int subject_len,
zval *replace_val, int is_callable_replace,
- int *result_len, int limit TSRMLS_DC)
+ int *result_len, int limit, int *replace_count TSRMLS_DC)
{
pcre *re = NULL; /* Compiled regular expression */
pcre_extra *extra = NULL; /* Holds results of studying */
@@ -895,9 +898,12 @@ PHPAPI char *php_pcre_replace(char *regex, int regex_len,
piece = subject + start_offset;
if (count > 0 && (limit == -1 || limit > 0)) {
+ if (replace_count) {
+ ++*replace_count;
+ }
/* Set the match location in subject */
match = subject + offsets[0];
-
+
new_len = *result_len + offsets[0] - start_offset; /* part before the match */
/* If evaluating, do it and add the return string's length */
@@ -1027,7 +1033,7 @@ PHPAPI char *php_pcre_replace(char *regex, int regex_len,
/* {{{ php_replace_in_subject
*/
-static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, int *result_len, int limit, zend_bool is_callable_replace TSRMLS_DC)
+static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, int *result_len, int limit, zend_bool is_callable_replace, int *replace_count TSRMLS_DC)
{
zval **regex_entry,
**replace_entry = NULL,
@@ -1039,7 +1045,8 @@ static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject,
/* Make sure we're dealing with strings. */
convert_to_string_ex(subject);
- ZVAL_STRINGL(&empty_replace, empty_string, 0, 0);
+ /* FIXME: This might need to be changed to STR_EMPTY_ALLOC(). Check if this zval could be dtor()'ed somehow */
+ ZVAL_STRINGL(&empty_replace, "", 0, 0);
/* If regex is an array */
if (Z_TYPE_P(regex) == IS_ARRAY) {
@@ -1083,7 +1090,8 @@ static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject,
replace_value,
is_callable_replace,
result_len,
- limit TSRMLS_CC)) != NULL) {
+ limit,
+ replace_count TSRMLS_CC)) != NULL) {
efree(subject_value);
subject_value = result;
subject_len = *result_len;
@@ -1101,7 +1109,8 @@ static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject,
replace,
is_callable_replace,
result_len,
- limit TSRMLS_CC);
+ limit,
+ replace_count TSRMLS_CC);
return result;
}
}
@@ -1115,17 +1124,20 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_callabl
**replace,
**subject,
**limit,
- **subject_entry;
+ **subject_entry,
+ **zcount;
char *result;
int result_len;
int limit_val = -1;
char *string_key;
ulong num_key;
char *callback_name = NULL;
+ int replace_count=0;
+ int *replace_count_ptr=NULL;
/* Get function parameters and do error-checking. */
- if (ZEND_NUM_ARGS() < 3 || ZEND_NUM_ARGS() > 4 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &regex, &replace, &subject, &limit) == FAILURE) {
+ if (ZEND_NUM_ARGS() < 3 || ZEND_NUM_ARGS() > 5 ||
+ zend_get_parameters_ex(ZEND_NUM_ARGS(), &regex, &replace, &subject, &limit, &zcount) == FAILURE) {
WRONG_PARAM_COUNT;
}
if (!is_callable_replace && Z_TYPE_PP(replace) == IS_ARRAY && Z_TYPE_PP(regex) != IS_ARRAY) {
@@ -1154,6 +1166,9 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_callabl
convert_to_long_ex(limit);
limit_val = Z_LVAL_PP(limit);
}
+ if (ZEND_NUM_ARGS() > 4) {
+ replace_count_ptr =& replace_count;
+ }
if (Z_TYPE_PP(regex) != IS_ARRAY)
convert_to_string_ex(regex);
@@ -1167,7 +1182,7 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_callabl
and add the result to the return_value array. */
while (zend_hash_get_current_data(Z_ARRVAL_PP(subject), (void **)&subject_entry) == SUCCESS) {
SEPARATE_ZVAL(subject_entry);
- if ((result = php_replace_in_subject(*regex, *replace, subject_entry, &result_len, limit_val, is_callable_replace TSRMLS_CC)) != NULL) {
+ if ((result = php_replace_in_subject(*regex, *replace, subject_entry, &result_len, limit_val, is_callable_replace, replace_count_ptr TSRMLS_CC)) != NULL) {
/* Add to return array */
switch(zend_hash_get_current_key(Z_ARRVAL_PP(subject), &string_key, &num_key, 0))
{
@@ -1183,16 +1198,20 @@ static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_callabl
zend_hash_move_forward(Z_ARRVAL_PP(subject));
}
- }
- else { /* if subject is not an array */
- if ((result = php_replace_in_subject(*regex, *replace, subject, &result_len, limit_val, is_callable_replace TSRMLS_CC)) != NULL) {
+ } else { /* if subject is not an array */
+ if ((result = php_replace_in_subject(*regex, *replace, subject, &result_len, limit_val, is_callable_replace, replace_count_ptr TSRMLS_CC)) != NULL) {
RETVAL_STRINGL(result, result_len, 0);
}
- }
+ }
+ if (replace_count_ptr) {
+ zval_dtor(*zcount);
+ ZVAL_LONG(*zcount, replace_count);
+ }
+
}
/* }}} */
-/* {{{ proto string preg_replace(mixed regex, mixed replace, mixed subject [, int limit])
+/* {{{ proto string preg_replace(mixed regex, mixed replace, mixed subject [, int limit [, count]])
Perform Perl-style regular expression replacement. */
PHP_FUNCTION(preg_replace)
{
@@ -1200,7 +1219,7 @@ PHP_FUNCTION(preg_replace)
}
/* }}} */
-/* {{{ proto string preg_replace_callback(mixed regex, mixed callback, mixed subject [, int limit])
+/* {{{ proto string preg_replace_callback(mixed regex, mixed callback, mixed subject [, int limit [, count]])
Perform Perl-style regular expression replacement using replacement callback. */
PHP_FUNCTION(preg_replace_callback)
{
@@ -1423,7 +1442,7 @@ PHP_FUNCTION(preg_quote)
/* Nothing to do if we got an empty string */
if (in_str == in_str_end) {
- RETVAL_STRINGL(empty_string, 0, 0);
+ RETURN_EMPTY_STRING();
}
if (ZEND_NUM_ARGS() == 2) {
diff --git a/ext/pcre/php_pcre.h b/ext/pcre/php_pcre.h
index 028017d5b..13bbe5196 100644
--- a/ext/pcre/php_pcre.h
+++ b/ext/pcre/php_pcre.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2004 The PHP Group |
+ | Copyright (c) 1997-2005 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_pcre.h,v 1.39 2004/02/01 03:02:47 moriyoshi Exp $ */
+/* $Id: php_pcre.h,v 1.41 2005/08/03 14:07:38 sniper Exp $ */
#ifndef PHP_PCRE_H
#define PHP_PCRE_H
@@ -41,7 +41,7 @@ PHP_FUNCTION(preg_split);
PHP_FUNCTION(preg_quote);
PHP_FUNCTION(preg_grep);
-PHPAPI char *php_pcre_replace(char *regex, int regex_len, char *subject, int subject_len, zval *replace_val, int is_callable_replace, int *result_len, int limit TSRMLS_DC);
+PHPAPI char *php_pcre_replace(char *regex, int regex_len, char *subject, int subject_len, zval *replace_val, int is_callable_replace, int *result_len, int limit, int *replace_count TSRMLS_DC);
PHPAPI pcre* pcre_get_compiled_regex(char *regex, pcre_extra **extra, int *options TSRMLS_DC);
PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *preg_options, int *coptions TSRMLS_DC);
diff --git a/ext/pcre/tests/bug34790.phpt b/ext/pcre/tests/bug34790.phpt
new file mode 100755
index 000000000..5baec5793
--- /dev/null
+++ b/ext/pcre/tests/bug34790.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Bug #34790 (preg_match_all(), named capturing groups, variable assignment/return => crash)
+--FILE--
+<?php
+function func1(){
+ $string = 'what the word and the other word the';
+ preg_match_all('/(?P<word>the)/', $string, $matches);
+ return $matches['word'];
+}
+$words = func1();
+var_dump($words);
+?>
+--EXPECT--
+array(4) {
+ [0]=>
+ string(3) "the"
+ [1]=>
+ string(3) "the"
+ [2]=>
+ string(3) "the"
+ [3]=>
+ string(3) "the"
+}
diff --git a/ext/pcre/tests/pcre_count.phpt b/ext/pcre/tests/pcre_count.phpt
new file mode 100644
index 000000000..1239d48ff
--- /dev/null
+++ b/ext/pcre/tests/pcre_count.phpt
@@ -0,0 +1,40 @@
+--TEST--
+preg_replace() fifth parameter - count
+--FILE--
+<?php
+$regex = '/(([0-9a-z]+)-([0-9]+))-(([0-9]+)-([0-9]+))/';
+
+$string= '1-2-3-4 a-2-3-4 1-a-3-4 1-2-a-4 1-2-3-a a-a-a-a 4-3-2-1 100-200-300-400-500-600-700-800';
+$count = 0;
+var_dump(preg_replace($regex, 'xxxx', $string, -1, $count));
+var_dump($count);
+//////////////////////////////////////////////////////
+
+$regex = '/([a-z]+)/';
+
+$string= 'Here must only number like 42 and 13 appear';
+var_dump(preg_replace($regex, 'xxxx', $string, -1, $count));
+var_dump($count);
+
+////////////////////////////////////////////////////////
+$regex = '~((V(I|1)(4|A)GR(4|A))|(V(I|1)C(0|O)D(I|1)(N|\/\\\/)))~i';
+
+$string= 'Viagra V14GR4 Vicodin V1C0D1/\/ v1c0d1/|/';
+var_dump(preg_replace($regex, '...', $string, -1, $count));
+var_dump($count);
+////////////////////////////////////////////////////////
+$regex = '~((V(I|1)(4|A)GR(4|A))|(V(I|1)C(0|O)D(I|1)(N|\/\\\/)))~i';
+$count = NULL;
+$string= 'Viagra V14GR4 Vicodin V1C0D1/\/ v1c0d1/|/';
+var_dump(preg_replace($regex, '...', $string, -1));
+var_dump($count);
+?>
+--EXPECT--
+string(56) "xxxx xxxx 1-a-3-4 1-2-a-4 1-2-3-a a-a-a-a xxxx xxxx-xxxx"
+int(5)
+string(41) "Hxxxx xxxx xxxx xxxx xxxx 42 xxxx 13 xxxx"
+int(7)
+string(25) "... ... ... ... v1c0d1/|/"
+int(4)
+string(25) "... ... ... ... v1c0d1/|/"
+NULL