Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CONFSERVER-82911 Back-port https://github.com/hunterhacker/jdom/pull/188 #1

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions core/src/java/org/jdom/input/SAXBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -758,16 +758,8 @@ protected void configureParser(XMLReader parser, SAXHandler contentHandler)
private void setFeaturesAndProperties(XMLReader parser,
boolean coreFeatures)
throws JDOMException {
// Set any user-specified features on the parser.
Iterator iter = features.keySet().iterator();
while (iter.hasNext()) {
String name = (String)iter.next();
Boolean value = (Boolean)features.get(name);
internalSetFeature(parser, name, value.booleanValue(), name);
}

// Set any user-specified properties on the parser.
iter = properties.keySet().iterator();
Iterator iter = properties.keySet().iterator();
while (iter.hasNext()) {
String name = (String)iter.next();
internalSetProperty(parser, name, properties.get(name), name);
Expand Down Expand Up @@ -810,6 +802,14 @@ private void setFeaturesAndProperties(XMLReader parser,
}
catch (SAXNotRecognizedException e) { /* Ignore... */ }
catch (SAXNotSupportedException e) { /* Ignore... */ }

// Set any user-specified features on the parser.
iter = features.keySet().iterator();
while (iter.hasNext()) {
String name = (String)iter.next();
Boolean value = (Boolean)features.get(name);
internalSetFeature(parser, name, value.booleanValue(), name);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also remove the redundant setting of user-specified features from above this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I didn't do that initially just to minimise the code change, but that's ok.

}

/**
Expand Down
19 changes: 19 additions & 0 deletions test/src/java/org/jdom/test/cases/input/TestSAXBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,25 @@ public void testCreateParser() {
// }
// }

public void testSetExternalFeature() {
String feature = "http://xml.org/sax/features/external-general-entities";
MySAXBuilder sb = new MySAXBuilder();
try {
sb.setFeature(feature, true);
XMLReader reader = sb.createParser();
assertNotNull(reader);
assertTrue(reader.getFeature(feature));
sb.setFeature(feature, false);
reader = sb.createParser();
assertNotNull(reader);
assertFalse(reader.getFeature(feature));

} catch (Exception e) {
e.printStackTrace();
fail("Could not create parser: " + e.getMessage());
}
}

public void testSetProperty() {
LexicalHandler lh = new LexicalHandler() {

Expand Down