Skip to content

Commit

Permalink
Fix an issue where $ in regular expressions in Substitution filters w…
Browse files Browse the repository at this point in the history
…ould not always work correctly if the "Ignore carriage return differences" option was enabled. (refs WinMerge#2640)
  • Loading branch information
sdottaka committed Feb 12, 2025
1 parent a678745 commit 7e8c711
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions Externals/poco/Foundation/include/Poco/RegularExpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Foundation_API RegularExpression
RE_NEWLINE_CRLF = 0x00300000, /// assume newline is CRLF ("\r\n") [ctor]
RE_NEWLINE_ANY = 0x00400000, /// assume newline is any valid Unicode newline character [ctor]
RE_NEWLINE_ANYCRLF = 0x00500000, /// assume newline is any of CR, LF, CRLF [ctor]
RE_NEWLINE_MASK = 0x00F00000,
RE_GLOBAL = 0x10000000, /// replace all occurences (/g) [subst]
RE_NO_VARS = 0x20000000 /// treat dollar in replacement string as ordinary character [subst]
};
Expand Down
8 changes: 4 additions & 4 deletions Externals/poco/Foundation/src/RegularExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ RegularExpression::RegularExpression(const std::string& pattern, int options, bo
pcre2_compile_context* context = pcre2_compile_context_create(nullptr);
if (!context) throw Poco::RegularExpressionException("cannot create compile context");

if (options & RE_NEWLINE_LF)
if ((options & RE_NEWLINE_MASK) == RE_NEWLINE_LF)
pcre2_set_newline(context, PCRE2_NEWLINE_LF);
else if (options & RE_NEWLINE_CRLF)
else if ((options & RE_NEWLINE_MASK) == RE_NEWLINE_CRLF)
pcre2_set_newline(context, PCRE2_NEWLINE_CRLF);
else if (options & RE_NEWLINE_ANY)
else if ((options & RE_NEWLINE_MASK) == RE_NEWLINE_ANY)
pcre2_set_newline(context, PCRE2_NEWLINE_ANY);
else if (options & RE_NEWLINE_ANYCRLF)
else if ((options & RE_NEWLINE_MASK) == RE_NEWLINE_ANYCRLF)
pcre2_set_newline(context, PCRE2_NEWLINE_ANYCRLF);
else // default RE_NEWLINE_CR
pcre2_set_newline(context, PCRE2_NEWLINE_CR);
Expand Down
2 changes: 1 addition & 1 deletion Src/SubstitutionFiltersList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ std::shared_ptr<SubstitutionList> SubstitutionFiltersList::MakeSubstitutionList(
ucr::toUTF8(item.pattern),
ucr::toUTF8(item.replacement),
(item.caseSensitive ? 0 : Poco::RegularExpression::RE_CASELESS) |
Poco::RegularExpression::RE_MULTILINE);
Poco::RegularExpression::RE_MULTILINE | Poco::RegularExpression::RE_NEWLINE_ANYCRLF);
}
else
{
Expand Down

0 comments on commit 7e8c711

Please sign in to comment.