aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2018-04-13 08:48:23 +1000
committerNeil <nyamatongwe@gmail.com>2018-04-13 08:48:23 +1000
commit50eca9beb97b7c69f15d1ce96dddb5e2efc3a0e8 (patch)
tree7d43c45205e6d7e376ad7f90c007751aa9931d6e
parentddbc7d46f93d87773a2713281591fc4e9c5baeca (diff)
downloadscintilla-mirror-50eca9beb97b7c69f15d1ce96dddb5e2efc3a0e8.tar.gz
Fix bug with regular expression searches failing to match at line start or end.
This was a work-around for infinite loops when replacing empty matches and this is now the application's responsibility.
-rw-r--r--doc/ScintillaHistory.html8
-rw-r--r--src/Document.cxx20
2 files changed, 12 insertions, 16 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index d19e64383..87bfa49ab 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -545,6 +545,14 @@
Set the last X chosen when SCI_REPLACESEL called to ensure macros work
when text insertion followed by caret up or down.
</li>
+ <li>
+ Bugs fixed in regular expression searches in Scintilla where some matches did not occur in an
+ effort to avoid infinite loops when replacing on empty matches like "^" and "$".
+ Applications should always handle empty matches in a way that avoids infinite loops, commonly
+ by incrementing the search position after replacing an empty match.
+ SciTE fixes a bug where replacing "^" always matched on the first line even when it was an
+ "in selection" replace and the selection started after the line start.
+ </li>
</ul>
<h3>
<a href="https://www.scintilla.org/scite404.zip">Release 4.0.4</a>
diff --git a/src/Document.cxx b/src/Document.cxx
index 3b70432e3..b3b445b02 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -2533,25 +2533,13 @@ public:
RESearchRange(const Document *doc_, Sci::Position minPos, Sci::Position maxPos) : doc(doc_) {
increment = (minPos <= maxPos) ? 1 : -1;
- // Range endpoints should not be inside DBCS characters, but just in case, move them.
- startPos = doc->MovePositionOutsideChar(minPos, 1, false);
- endPos = doc->MovePositionOutsideChar(maxPos, 1, false);
+ // Range endpoints should not be inside DBCS characters or between a CR and LF,
+ // but just in case, move them.
+ startPos = doc->MovePositionOutsideChar(minPos, 1, true);
+ endPos = doc->MovePositionOutsideChar(maxPos, 1, true);
lineRangeStart = static_cast<Sci::Line>(doc->LineFromPosition(startPos));
lineRangeEnd = static_cast<Sci::Line>(doc->LineFromPosition(endPos));
- if ((increment == 1) &&
- (startPos >= doc->LineEnd(lineRangeStart)) &&
- (lineRangeStart < lineRangeEnd)) {
- // the start position is at end of line or between line end characters.
- lineRangeStart++;
- startPos = static_cast<Sci::Position>(doc->LineStart(lineRangeStart));
- } else if ((increment == -1) &&
- (startPos <= doc->LineStart(lineRangeStart)) &&
- (lineRangeStart > lineRangeEnd)) {
- // the start position is at beginning of line.
- lineRangeStart--;
- startPos = static_cast<Sci::Position>(doc->LineEnd(lineRangeStart));
- }
lineRangeBreak = lineRangeEnd + increment;
}
Range LineRange(Sci::Line line) const {