Skip to content

Commit

Permalink
Merge pull request #188 from esti-burstein/SetFeatureBugFix
Browse files Browse the repository at this point in the history
fix setFeature bug and add test case
  • Loading branch information
hunterhacker authored Jun 24, 2021
2 parents 3c4e2cf + bd3ab78 commit 2a25ee4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
10 changes: 4 additions & 6 deletions core/src/java/org/jdom2/input/SAXBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -971,11 +971,6 @@ protected void configureParser(final XMLReader parser, final SAXHandler contentH
}
}

// Set any user-specified features on the parser.
for (final Map.Entry<String, Boolean> me : features.entrySet()) {
internalSetFeature(parser, me.getKey(), me.getValue().booleanValue(), me.getKey());
}

// Set any user-specified properties on the parser.
for (final Map.Entry<String, Object> me : properties.entrySet()) {
internalSetProperty(parser, me.getKey(), me.getValue(), me.getKey());
Expand Down Expand Up @@ -1007,7 +1002,10 @@ protected void configureParser(final XMLReader parser, final SAXHandler contentH
// No lexical reporting available
}
}

// Set any user-specified features on the parser.
for (final Map.Entry<String, Boolean> me : features.entrySet()) {
internalSetFeature(parser, me.getKey(), me.getValue().booleanValue(), me.getKey());
}
}

/**
Expand Down
20 changes: 20 additions & 0 deletions test/src/java/org/jdom2/test/cases/input/TestSAXBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,26 @@ public void testSetFeature() {
}
}

@Test
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());
}
}

@Test
public void testSetProperty() {
LexicalHandler lh = new LexicalHandler() {
Expand Down

0 comments on commit 2a25ee4

Please sign in to comment.