cvs: php4 /ext/pcre php_pcre.c

From: Date: Mon, 13 Nov 2000 19:49:41 +0000
Subject: cvs: php4 /ext/pcre php_pcre.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-2593@lists.php.net to get a copy of this message
andrei Mon Nov 13 11:49:41 2000 EDT Modified files: /php4/ext/pcre php_pcre.c Log: @- Modified preg_replace() to ignore backreferences that refer to @ non-existing subpatterns. (Andrei) Index: php4/ext/pcre/php_pcre.c diff -u php4/ext/pcre/php_pcre.c:1.69 php4/ext/pcre/php_pcre.c:1.70 --- php4/ext/pcre/php_pcre.c:1.69 Thu Sep 14 08:44:36 2000 +++ php4/ext/pcre/php_pcre.c Mon Nov 13 11:49:41 2000 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_pcre.c,v 1.69 2000/09/14 15:44:36 andrei Exp $ */ +/* $Id: php_pcre.c,v 1.70 2000/11/13 19:49:41 andrei Exp $ */ /* TODO: @@ -555,16 +555,22 @@ while (*walk) { /* If found a backreference.. */ - if ('\\' == *walk && preg_get_backref(walk+1, &backref) && backref < count) { - /* Find the corresponding string match and substitute it - in instead of the backref */ - match = subject + offsets[backref<<1]; - match_len = offsets[(backref<<1)+1] - offsets[backref<<1]; - if (match_len) - esc_match = php_addslashes(match, match_len, &esc_match_len, 0); - else { - esc_match = match; + if ('\\' == *walk && preg_get_backref(walk+1, &backref)) { + if (backref < count) { + /* Find the corresponding string match and substitute it + in instead of the backref */ + match = subject + offsets[backref<<1]; + match_len = offsets[(backref<<1)+1] - offsets[backref<<1]; + if (match_len) + esc_match = php_addslashes(match, match_len, &esc_match_len, 0); + else { + esc_match = match; + esc_match_len = 0; + } + } else { + esc_match = empty_string; esc_match_len = 0; + match_len = 0; } sprintf(backref_buf, "\\%d", backref); new_code = php_str_to_str(code, code_len, @@ -688,8 +694,9 @@ } else { /* do regular substitution */ walk = replace; while (walk < replace_end) - if ('\\' == *walk && preg_get_backref(walk+1, &backref) && backref < count) { - new_len += offsets[(backref<<1)+1] - offsets[backref<<1]; + if ('\\' == *walk && preg_get_backref(walk+1, &backref)) { + if (backref < count) + new_len += offsets[(backref<<1)+1] - offsets[backref<<1]; walk += (backref > 9) ? 3 : 2; } else { new_len++; @@ -719,10 +726,12 @@ } else { /* do regular backreference copying */ walk = replace; while (walk < replace_end) - if ('\\' == *walk && preg_get_backref(walk+1, &backref) && backref < count) { - match_len = offsets[(backref<<1)+1] - offsets[backref<<1]; - memcpy(walkbuf, subject + offsets[backref<<1], match_len); - walkbuf += match_len; + if ('\\' == *walk && preg_get_backref(walk+1, &backref)) { + if (backref < count) { + match_len = offsets[(backref<<1)+1] - offsets[backref<<1]; + memcpy(walkbuf, subject + offsets[backref<<1], match_len); + walkbuf += match_len; + } walk += (backref > 9) ? 3 : 2; } else { *walkbuf++ = *walk++;

« previous php.cvs (#2593) next »