You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2016/07/29 00:02:31 UTC

[5/7] groovy git commit: GROOVY-7563: InvokerHelper: Map formatting safe and self-detecting also for keys

GROOVY-7563: InvokerHelper: Map formatting safe and self-detecting also for keys


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/56904d6e
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/56904d6e
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/56904d6e

Branch: refs/heads/master
Commit: 56904d6e2d5022d6ae4e70374971a663b06b22a4
Parents: e28f001
Author: Thibault Kruse <th...@gmx.de>
Authored: Fri Aug 21 16:23:37 2015 +0200
Committer: paulk <pa...@asert.com.au>
Committed: Fri Jul 29 08:36:45 2016 +1000

----------------------------------------------------------------------
 src/main/org/codehaus/groovy/runtime/InvokerHelper.java   |  6 +++++-
 .../groovy/runtime/InvokerHelperFormattingTest.groovy     | 10 ++--------
 2 files changed, 7 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/56904d6e/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/InvokerHelper.java b/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
index 53055f0..17f7ca9 100644
--- a/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
+++ b/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
@@ -680,7 +680,11 @@ public class InvokerHelper {
                 break;
             }
             Map.Entry entry = (Map.Entry) o;
-            buffer.append(format(entry.getKey(), verbose));
+            if (entry.getKey() == map) {
+                buffer.append("(this Map)");
+            } else {
+                buffer.append(format(entry.getKey(), verbose, sizeLeft(maxSize, buffer), safe));
+            }
             buffer.append(":");
             if (entry.getValue() == map) {
                 buffer.append("(this Map)");

http://git-wip-us.apache.org/repos/asf/groovy/blob/56904d6e/src/test/org/codehaus/groovy/runtime/InvokerHelperFormattingTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/runtime/InvokerHelperFormattingTest.groovy b/src/test/org/codehaus/groovy/runtime/InvokerHelperFormattingTest.groovy
index bed83fa..4e55623 100644
--- a/src/test/org/codehaus/groovy/runtime/InvokerHelperFormattingTest.groovy
+++ b/src/test/org/codehaus/groovy/runtime/InvokerHelperFormattingTest.groovy
@@ -208,14 +208,8 @@ class InvokerHelperFormattingTest extends GroovyTestCase {
         assert '[(this Collection)]' == InvokerHelper.toString(l)
 
         Map m = [:]
-        m.put('x', m)
-        assert '[x:(this Map)]' == InvokerHelper.toString(m)
-
-        Map m2 = [:]
-        m2.put(m2, m2)
-        shouldFail(StackOverflowError) {
-            InvokerHelper.toString(m2)
-        }
+        m.put(m, m)
+        assert '[(this Map):(this Map)]' == InvokerHelper.toString(m)
     }
 
 }