|
2 | 2 |
|
3 | 3 | import static io.github.pixee.security.XMLInputFactorySecurity.hardenFactory; |
4 | 4 |
|
| 5 | +import com.ctc.wstx.evt.CompactStartElement; |
| 6 | +import com.ctc.wstx.stax.WstxInputFactory; |
5 | 7 | import java.io.ByteArrayInputStream; |
6 | 8 | import java.io.IOException; |
7 | 9 | import java.io.InputStream; |
@@ -38,7 +40,7 @@ class FormatCommand extends AbstractCommand { |
38 | 40 | private static final Logger LOGGER = LoggerFactory.getLogger(FormatCommand.class); |
39 | 41 |
|
40 | 42 | /** StAX InputFactory */ |
41 | | - private XMLInputFactory inputFactory = hardenFactory(XMLInputFactory.newInstance()); |
| 43 | + private XMLInputFactory inputFactory = WstxInputFactory.newInstance(); |
42 | 44 |
|
43 | 45 | /** StAX OutputFactory */ |
44 | 46 | private XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); |
@@ -270,6 +272,10 @@ private void parseXmlAndCharset(POMDocument pomFile) throws XMLStreamException, |
270 | 272 | int elementStart = 0; |
271 | 273 | List<XMLEvent> prevEvents = new ArrayList<>(); |
272 | 274 |
|
| 275 | + System.out.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="); |
| 276 | + System.out.println(inputFactory.getClass()); |
| 277 | + System.out.println(eventReader.getClass()); |
| 278 | + System.out.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="); |
273 | 279 | while (eventReader.hasNext()) { |
274 | 280 | XMLEvent event = eventReader.nextEvent(); |
275 | 281 |
|
@@ -324,8 +330,15 @@ private void parseXmlAndCharset(POMDocument pomFile) throws XMLStreamException, |
324 | 330 | String originalPomCharsetString = |
325 | 331 | new String(pomFile.getOriginalPom(), pomFile.getCharset()); |
326 | 332 |
|
327 | | - String untrimmedOriginalContent = |
328 | | - originalPomCharsetString.substring(elementStart, offset); |
| 333 | + String untrimmedOriginalContent = ""; |
| 334 | + // is self closing element, tag is contained within the offset of the next element |
| 335 | + if (prevEvents.get(prevEvents.size() - 1) instanceof CompactStartElement) { |
| 336 | + untrimmedOriginalContent = |
| 337 | + originalPomCharsetString.substring( |
| 338 | + offset, eventReader.peek().getLocation().getCharacterOffset()); |
| 339 | + } else { |
| 340 | + untrimmedOriginalContent = originalPomCharsetString.substring(elementStart, offset); |
| 341 | + } |
329 | 342 |
|
330 | 343 | String trimmedOriginalContent = untrimmedOriginalContent.trim(); |
331 | 344 |
|
|
0 commit comments