You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2021/11/17 16:44:44 UTC

[tika] branch main updated: TIKA-3551 TikaConfig: unspecified attribute of "xml-reader-utils" breaks configuration file parser (#452)

This is an automated email from the ASF dual-hosted git repository.

tallison pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git


The following commit(s) were added to refs/heads/main by this push:
     new 9d6a875  TIKA-3551 TikaConfig: unspecified attribute of "xml-reader-utils" breaks configuration file parser (#452)
9d6a875 is described below

commit 9d6a87576908ba2a27ecd403bae1a708ceb93483
Author: Sebastian Nagel <sn...@apache.org>
AuthorDate: Wed Nov 17 17:44:39 2021 +0100

    TIKA-3551 TikaConfig: unspecified attribute of "xml-reader-utils" breaks configuration file parser (#452)
    
    Thank you! I much prefer this PR to what I did.
---
 .../java/org/apache/tika/config/TikaConfig.java     | 13 ++++++-------
 .../java/org/apache/tika/config/TikaConfigTest.java |  6 ++++++
 .../apache/tika/config/TIKA-3551-xmlreaderutils.xml | 21 +++++++++++++++++++++
 3 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java b/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java
index c1f5380..cc8e000 100644
--- a/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java
+++ b/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java
@@ -493,15 +493,14 @@ public class TikaConfig {
         if (child == null) {
             return;
         }
-        String attr = child.getAttribute("maxEntityExpansions");
-        if (!StringUtils.isBlank(attr)) {
-            XMLReaderUtils.setMaxEntityExpansions(Integer.parseInt(attr));
+
+        if (child.hasAttribute("maxEntityExpansions")) {
+            XMLReaderUtils.setMaxEntityExpansions(Integer.parseInt(child.getAttribute("maxEntityExpansions")));
         }
 
-        //make sure to call this after set entity expansions
-        attr = child.getAttribute("poolSize");
-        if (!StringUtils.isBlank(attr)) {
-            XMLReaderUtils.setPoolSize(Integer.parseInt(attr));
+        // make sure to call this after set entity expansions
+        if (child.hasAttribute("poolSize")) {
+            XMLReaderUtils.setPoolSize(Integer.parseInt(child.getAttribute("poolSize")));
         }
 
     }
diff --git a/tika-core/src/test/java/org/apache/tika/config/TikaConfigTest.java b/tika-core/src/test/java/org/apache/tika/config/TikaConfigTest.java
index e9cb693..83ea7b2 100644
--- a/tika-core/src/test/java/org/apache/tika/config/TikaConfigTest.java
+++ b/tika-core/src/test/java/org/apache/tika/config/TikaConfigTest.java
@@ -360,6 +360,12 @@ public class TikaConfigTest extends AbstractTikaConfigTest {
     }
 
     @Test
+    public void testXMLReaderUtilsUnspecifiedAttribute() throws Exception {
+        TikaConfig tikaConfig = getConfig("TIKA-3551-xmlreaderutils.xml");
+        assertEquals(XMLReaderUtils.DEFAULT_MAX_ENTITY_EXPANSIONS, XMLReaderUtils.getMaxEntityExpansions());
+    }
+
+    @Test
     public void testBadExclude() throws Exception {
         assertThrows(TikaConfigException.class, () -> {
             getConfig("TIKA-3268-bad-parser-exclude.xml");
diff --git a/tika-core/src/test/resources/org/apache/tika/config/TIKA-3551-xmlreaderutils.xml b/tika-core/src/test/resources/org/apache/tika/config/TIKA-3551-xmlreaderutils.xml
new file mode 100644
index 0000000..a36bbc2
--- /dev/null
+++ b/tika-core/src/test/resources/org/apache/tika/config/TIKA-3551-xmlreaderutils.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<properties>
+    <!-- maxEntityExpansions="..." is not defined, should take the default value -->
+    <xml-reader-utils poolSize="10"/>
+</properties>