|
2 | 2 |
|
3 | 3 | import static io.github.pixee.security.XMLInputFactorySecurity.hardenFactory; |
4 | 4 |
|
5 | | -import com.ctc.wstx.evt.CompactStartElement; |
6 | 5 | import com.ctc.wstx.stax.WstxInputFactory; |
7 | 6 | import com.ctc.wstx.stax.WstxOutputFactory; |
8 | 7 | import java.io.ByteArrayInputStream; |
@@ -327,14 +326,26 @@ private void parseXmlAndCharset(POMDocument pomFile) throws XMLStreamException, |
327 | 326 | String originalPomCharsetString = |
328 | 327 | new String(pomFile.getOriginalPom(), pomFile.getCharset()); |
329 | 328 |
|
| 329 | + var prev = prevEvents.get(prevEvents.size() - 1); |
330 | 330 | String untrimmedOriginalContent = ""; |
331 | 331 | // is self-closing element, tag is contained within the offset of the next element |
332 | | - if (prevEvents.get(prevEvents.size() - 1) instanceof CompactStartElement) { |
| 332 | + if (prev instanceof StartElement |
| 333 | + && prev.getLocation().getCharacterOffset() |
| 334 | + == endElementEvent.getLocation().getCharacterOffset()) { |
333 | 335 | untrimmedOriginalContent = |
334 | 336 | originalPomCharsetString.substring( |
335 | 337 | offset, eventReader.peek().getLocation().getCharacterOffset()); |
336 | 338 | } else { |
337 | | - untrimmedOriginalContent = originalPomCharsetString.substring(elementStart, offset); |
| 339 | + // is empty tag, the last character events is not in between the tags |
| 340 | + if (prev.isStartElement()) { |
| 341 | + untrimmedOriginalContent = |
| 342 | + originalPomCharsetString.substring( |
| 343 | + prev.getLocation().getCharacterOffset(), |
| 344 | + eventReader.peek().getLocation().getCharacterOffset()); |
| 345 | + |
| 346 | + } else { |
| 347 | + untrimmedOriginalContent = originalPomCharsetString.substring(elementStart, offset); |
| 348 | + } |
338 | 349 | } |
339 | 350 |
|
340 | 351 | String trimmedOriginalContent = untrimmedOriginalContent.trim(); |
|
0 commit comments