Skip to content

Commit d167eb3

Browse files
committed
Fixed issue with some codemods that target XML files
1 parent 686fee5 commit d167eb3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

framework/codemodder-base/src/main/java/io/codemodder/DefaultXPathStreamProcessor.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,14 @@ public Optional<XPathStreamProcessChange> process(
7373
XMLEventWriter xmlWriter = outputFactory.createXMLEventWriter(sw);
7474
while (xmlReader.hasNext()) {
7575
final XMLEvent currentEvent = xmlReader.nextEvent();
76-
Location location = currentEvent.getLocation();
77-
if (doesPositionMatch(httpMethodPositions, location)) {
78-
handler.handle(xmlReader, xmlWriter, currentEvent);
76+
// get the position of the last character of the event, that is, the start of the next one
77+
if (xmlReader.hasNext()) {
78+
Location location = xmlReader.peek().getLocation();
79+
if (doesPositionMatch(httpMethodPositions, location)) {
80+
handler.handle(xmlReader, xmlWriter, currentEvent);
81+
} else {
82+
xmlWriter.add(currentEvent);
83+
}
7984
} else {
8085
xmlWriter.add(currentEvent);
8186
}

0 commit comments

Comments
 (0)