Skip to content

Commit

Permalink
Backport #214 fix in 6.7 branch (just in case we'd release from it) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Nov 12, 2024
1 parent 21faf99 commit e8fb06a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
6 changes: 6 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Project: woodstox
=== Releases ===
------------------------------------------------------------------------

6.7.1 (not yet released)

#213: SAX: `Locator#getSystemId` and `Locator#getPublicId` are not
available during `startDocument` event
(fix contributed by Philipp N)

6.7.0 (21-Jun-2024)

#204: Non-conformant `XMLEventFactory.setLocation(null)`
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/ctc/wstx/sax/WstxSAXParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -579,14 +579,8 @@ public void parse(InputSource input) throws SAXException
}
}

if (mContentHandler != null) {
mContentHandler.setDocumentLocator(this);
mContentHandler.startDocument();
}

/* Note: since we are reusing the same config instance, need to
* make sure state is not carried forward. Thus:
*/
// Note: since we are reusing the same config instance, need to
// make sure state is not carried forward. Thus:
cfg.resetState();

try {
Expand Down Expand Up @@ -620,6 +614,12 @@ public void parse(InputSource input) throws SAXException
mStandalone = mScanner.standaloneSet();
mAttrCollector = mScanner.getAttributeCollector();
mElemStack = mScanner.getInputElementStack();

if (mContentHandler != null) {
mContentHandler.setDocumentLocator(this);
mContentHandler.startDocument();
}

fireEvents();
} catch (IOException io) {
throwSaxException(io);
Expand Down
17 changes: 15 additions & 2 deletions src/test/java/wstxtest/sax/TestBasicSax.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class TestBasicSax
+"<!DOCTYPE root []>"
+"<root><!-- comment -->"
+"<leaf attr='a&amp;b!'>rock&apos;n <![CDATA[roll]]></leaf><?proc instr?></root> ";
final static String DOCUMENT_SYSTEMID = "document.xml";

public void testSimpleNs()
throws Exception
Expand Down Expand Up @@ -89,8 +90,10 @@ public void doTestSimple(boolean ns, boolean useReader)
} else {
src = new InputSource(new ByteArrayInputStream(XML.getBytes("UTF-8")));
}
src.setSystemId(DOCUMENT_SYSTEMID);

sp.parse(src, h);
assertEquals(DOCUMENT_SYSTEMID, h._systemId);
assertEquals(2, h._elems);
assertEquals(1, h._attrs);
assertEquals(11, h._charCount);
Expand All @@ -111,9 +114,19 @@ public String getText() {
final static class MyHandler
extends DefaultHandler
{
public int _elems, _attrs;
public int _elems, _attrs, _charCount;
public String _systemId;
private Locator locator;

public int _charCount;
@Override
public void setDocumentLocator(Locator locator) {
this.locator = locator;
}

@Override
public void startDocument() throws SAXException {
_systemId = locator.getSystemId();
}

@Override
public void characters(char[] ch, int start, int length) {
Expand Down

0 comments on commit e8fb06a

Please sign in to comment.