Skip to content

Commit 26cd69f

Browse files
committed
add range limit matcher region
1 parent 9d23a0c commit 26cd69f

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

.idea/misc.xml

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VERSION-TODO.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [Release 0.60.0](#release-0600)
88
- [API Refactoring](#api-refactoring)
99
- [Next 0.61.xx](#next-061xx)
10+
- [0.61.16](#06116)
1011
- [0.61.14](#06114)
1112
- [0.61.12](#06112)
1213
- [0.61.10](#06110)
@@ -219,6 +220,11 @@ Please give feedback on the upcoming changes if you have concerns about breaking
219220
* [ ] Fix: Html converter to not add spaces between end of inline marker and next punctuation:
220221
`.,:;`
221222

223+
## 0.61.16
224+
225+
* Fix: add range limit to `Escaping.replaceAll(Pattern, BasedSequence, List<Range>, Replacer,
226+
ReplacedTextMapper)` when setting matcher range.
227+
222228
## 0.61.14
223229

224230
* Fix: [#398, Autolinks get cut off if they contain \`&amp;\` (escaped query params)] for

flexmark-util-sequence/src/main/java/com/vladsch/flexmark/util/sequence/Escaping.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,6 @@ private static BasedSequence replaceAll(Pattern p, @NotNull BasedSequence s, int
696696
return textMapper.getReplacedSequence();
697697
}
698698

699-
700699
@NotNull
701700
private static BasedSequence replaceAll(Pattern p, @NotNull BasedSequence s, @NotNull List<Range> ranges, @NotNull Replacer replacer, @NotNull ReplacedTextMapper textMapper) {
702701
Matcher matcher = p.matcher(s);
@@ -709,15 +708,17 @@ private static BasedSequence replaceAll(Pattern p, @NotNull BasedSequence s, @No
709708
int lastEnd = 0;
710709

711710
for (Range range : ranges) {
712-
matcher.region(range.getStart(), range.getEnd());
713-
711+
int start = Utils.rangeLimit(range.getStart(), 0, s.length());
712+
int end = Utils.rangeLimit(range.getEnd(), start, s.length());
713+
matcher.region(start, end);
714+
714715
while (matcher.find()) {
715716
textMapper.addOriginalText(lastEnd, matcher.start());
716717
replacer.replace(s, matcher.start(), matcher.end(), textMapper);
717718
lastEnd = matcher.end();
718-
};
719+
}
719720
}
720-
721+
721722
if (lastEnd < s.length()) {
722723
textMapper.addOriginalText(lastEnd, s.length());
723724
}

0 commit comments

Comments
 (0)