lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From no...@apache.org
Subject lucene-solr:apiv2: SOLR-8029: avoid infinite loop
Date Thu, 29 Dec 2016 09:52:59 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/apiv2 03eca9c11 -> b55e25a99


SOLR-8029: avoid infinite loop


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/b55e25a9
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/b55e25a9
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/b55e25a9

Branch: refs/heads/apiv2
Commit: b55e25a9900f15db1c5ffbb2f2eb1f09c831f56f
Parents: 03eca9c
Author: Noble Paul <noble@apache.org>
Authored: Thu Dec 29 20:22:40 2016 +1030
Committer: Noble Paul <noble@apache.org>
Committed: Thu Dec 29 20:22:40 2016 +1030

----------------------------------------------------------------------
 .../apache/solr/common/util/ValidatingJsonMap.java  | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b55e25a9/solr/solrj/src/java/org/apache/solr/common/util/ValidatingJsonMap.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/ValidatingJsonMap.java b/solr/solrj/src/java/org/apache/solr/common/util/ValidatingJsonMap.java
index 95318af..7d007f0 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/ValidatingJsonMap.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/ValidatingJsonMap.java
@@ -249,7 +249,7 @@ public class ValidatingJsonMap implements Map<String, Object> {
   public static ValidatingJsonMap fromJSON(Reader s, String includeLocation) {
     try {
       ValidatingJsonMap map = (ValidatingJsonMap)getObjectBuilder(new JSONParser(s)).getObject();
-      handleIncludes(map, includeLocation);
+      handleIncludes(map, includeLocation, 4);
       return map;
     } catch (IOException e) {
       throw new RuntimeException();
@@ -260,17 +260,21 @@ public class ValidatingJsonMap implements Map<String, Object>
{
    * In the given map, recursively replace "#include":"resource-name" with the key/value
pairs 
    * parsed from the resource at {location}/{resource-name}.json
    */
-  private static void handleIncludes(ValidatingJsonMap map, String location) {
+  private static void handleIncludes(ValidatingJsonMap map, String location, int maxDepth)
{
     final String loc = location == null ? "" // trim trailing slash
-        : (location.endsWith("/") ? location.substring(0, location.length() - 1) : location);

-    String resourceToInclude = (String)map.get(INCLUDE);
+        : (location.endsWith("/") ? location.substring(0, location.length() - 1) : location);
+    String resourceToInclude = (String) map.get(INCLUDE);
     if (resourceToInclude != null) {
       ValidatingJsonMap includedMap = parse(loc + "/" + resourceToInclude + RESOURCE_EXTENSION,
loc);
       map.remove(INCLUDE);
       map.putAll(includedMap);
     }
-    map.entrySet().stream().filter(e->e.getValue() instanceof Map).map(Map.Entry::getValue)
-        .forEach(m->handleIncludes((ValidatingJsonMap)m, loc));
+    if (maxDepth > 0) {
+      map.entrySet().stream()
+          .filter(e -> e.getValue() instanceof Map)
+          .map(Map.Entry::getValue)
+          .forEach(m -> handleIncludes((ValidatingJsonMap) m, loc, maxDepth - 1));
+    }
   }
 
   public static ValidatingJsonMap getDeepCopy(Map map, int maxDepth, boolean mutable) {


Mime
View raw message