Skip to content

Commit 0ee1063

Browse files
committed
Fix updater for multiple matches where replacements change the length
1 parent 2608a79 commit 0ee1063

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

  • releng/org.eclipse.epp.config/org.eclipse.epp.releng.updater/src/org/eclipse/epp/releng/updater

releng/org.eclipse.epp.config/org.eclipse.epp.releng.updater/src/org/eclipse/epp/releng/updater/Updater.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,15 @@ private void apply(Path path, String pattern, String... replacements) throws IOE
171171
var matcher = Pattern.compile(pattern).matcher(content);
172172
if (matcher.find()) {
173173
var modifiedContent = new StringBuilder(content);
174+
var offset = 0;
174175
do {
176+
var delta = modifiedContent.length();
175177
for (var group = matcher.groupCount(); group >= 1; --group) {
176-
modifiedContent.replace(matcher.start(group), matcher.end(group), replacements[group - 1]);
178+
modifiedContent.replace(offset + matcher.start(group), offset + matcher.end(group),
179+
replacements[group - 1]);
177180
}
181+
delta -= modifiedContent.length();
182+
offset -= delta;
178183
} while (matcher.find());
179184
if (!modifiedContent.toString().equals(content)) {
180185
contents.put(path, modifiedContent.toString());

0 commit comments

Comments
 (0)