Skip to content

Commit

Permalink
#28 Disable downloading external resources with DocumentHelper.parseT…
Browse files Browse the repository at this point in the history
…ext() helper.

(cherry picked from commit 8f6a7f6)
  • Loading branch information
FilipJirsak committed Apr 11, 2020
1 parent 223ae06 commit 1707bf3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/org/dom4j/DocumentHelper.java
Expand Up @@ -270,6 +270,14 @@ public static void sort(List<Node> list, String expression, boolean distinct) {
*/
public static Document parseText(String text) throws DocumentException {
SAXReader reader = new SAXReader();
try {
reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
} catch (SAXException e) {
//Parse with external resources downloading allowed.
}

String encoding = getEncoding(text);

InputSource source = new InputSource(new StringReader(text));
Expand Down

0 comments on commit 1707bf3

Please sign in to comment.