summaryrefslogtreecommitdiff
path: root/src/pcre2_substitute.c
diff options
context:
space:
mode:
authorph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069>2015-11-13 16:52:26 +0000
committerph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069>2015-11-13 16:52:26 +0000
commiteda6dd2c83da55fad345fb19a51ff36ceb957167 (patch)
treebc53bea7192842262d9bb0518d24c37d57e3e2d1 /src/pcre2_substitute.c
parentbd8ab2aaf175c19ba75c03d599b5ade31eff62e3 (diff)
downloadpcre2-eda6dd2c83da55fad345fb19a51ff36ceb957167.tar.gz
Don't split CRLF in pcre2_substitute() when it's a valid newline sequence.
git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@430 6239d852-aaf2-0410-a92c-79f79f948069
Diffstat (limited to 'src/pcre2_substitute.c')
-rw-r--r--src/pcre2_substitute.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/pcre2_substitute.c b/src/pcre2_substitute.c
index 9ece6f6..94a329e 100644
--- a/src/pcre2_substitute.c
+++ b/src/pcre2_substitute.c
@@ -296,8 +296,22 @@ do
if (rc != PCRE2_ERROR_NOMATCH) goto EXIT;
if (goptions == 0 || start_offset >= length) break;
+ /* Advance by one code point. Then, if CRLF is a valid newline sequence and
+ we have advanced into the middle of it, advance one more code point. In
+ other words, do not start in the middle of CRLF, even if CR and LF on their
+ own are valid newlines. */
+
save_start = start_offset++;
- if ((code->overall_options & PCRE2_UTF) != 0)
+ if (subject[start_offset-1] == CHAR_CR &&
+ code->newline_convention != PCRE2_NEWLINE_CR &&
+ code->newline_convention != PCRE2_NEWLINE_LF &&
+ start_offset < length &&
+ subject[start_offset] == CHAR_LF)
+ start_offset++;
+
+ /* Otherwise, in UTF mode, advance past any secondary code points. */
+
+ else if ((code->overall_options & PCRE2_UTF) != 0)
{
#if PCRE2_CODE_UNIT_WIDTH == 8
while (start_offset < length && (subject[start_offset] & 0xc0) == 0x80)