groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Make `GProperties` support escaping empty curly brace, i.e. `{{}}`
Date Tue, 06 Nov 2018 15:40:27 GMT
Repository: groovy
Updated Branches:
  refs/heads/master ee2345816 -> 187617ea8


Make `GProperties` support escaping empty curly brace, i.e. `{{}}`


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

Branch: refs/heads/master
Commit: 187617ea83b3a845d8eab9af97c8d642ffd4cd44
Parents: ee23458
Author: danielsun1106 <realbluesun@hotmail.com>
Authored: Tue Nov 6 23:34:53 2018 +0800
Committer: Daniel Sun <sunlan@apache.org>
Committed: Tue Nov 6 23:38:57 2018 +0800

----------------------------------------------------------------------
 src/main/groovy/groovy/util/GProperties.groovy       | 15 +++++----------
 .../groovy/util/gproperties.properties               |  1 +
 src/test/groovy/util/GPropertiesTest.groovy          |  7 +++++++
 3 files changed, 13 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/187617ea/src/main/groovy/groovy/util/GProperties.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/util/GProperties.groovy b/src/main/groovy/groovy/util/GProperties.groovy
index efcdca1..fde01dc 100644
--- a/src/main/groovy/groovy/util/GProperties.groovy
+++ b/src/main/groovy/groovy/util/GProperties.groovy
@@ -86,7 +86,7 @@ class GProperties extends Properties {
     private static final long serialVersionUID = 6112578636029876860L
     public static final String IMPORT_PROPERTIES_KEY = 'import.properties'
     private static final Pattern INTERPOLATE_PATTERN = Pattern.compile(/[{](.+?)[}]/)
-    private static final Pattern ESCAPE_PATTERN = Pattern.compile(/[{]([{].+?[}])[}]/)
+    private static final Pattern ESCAPE_PATTERN = Pattern.compile(/[{]([{][^{}]*?[}])[}]/)
     private static final String LEFT_CURLY_BRACE = '{'
     private static final String RIGHT_CURLY_BRACE = '}'
     private static final String COMMA = ','
@@ -290,7 +290,7 @@ class GProperties extends Properties {
     synchronized void load(Reader reader) throws IOException {
         reader.withReader {
             super.load(it)
-            _importProperties()
+            importPropertiesFromFiles()
         }
     }
 
@@ -298,7 +298,7 @@ class GProperties extends Properties {
     synchronized void load(InputStream inStream) throws IOException {
         inStream.withStream {
             super.load(it)
-            _importProperties()
+            importPropertiesFromFiles()
         }
     }
 
@@ -310,7 +310,7 @@ class GProperties extends Properties {
         importPropertiesList << properties
     }
 
-    private void _importProperties() {
+    private void importPropertiesFromFiles() {
         String importPropertiesPaths = super.getProperty(IMPORT_PROPERTIES_KEY)
 
         if (!importPropertiesPaths?.trim()) {
@@ -322,18 +322,13 @@ class GProperties extends Properties {
                 return
             }
 
-            GProperties importProperties = new GProperties()
             def inputstream = GProperties.getResourceAsStream(importPropertiesPath)
 
             if (!inputstream) {
                 throw new IOException("${importPropertiesPath} does not exist")
             }
 
-            inputstream.withStream {
-                importProperties.load(it)
-            }
-
-            importPropertiesList << importProperties
+            importProperties(new GProperties(inputstream))
         }
     }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/187617ea/src/test-resources/groovy/util/gproperties.properties
----------------------------------------------------------------------
diff --git a/src/test-resources/groovy/util/gproperties.properties b/src/test-resources/groovy/util/gproperties.properties
index e096c48..3c68452 100644
--- a/src/test-resources/groovy/util/gproperties.properties
+++ b/src/test-resources/groovy/util/gproperties.properties
@@ -22,6 +22,7 @@ groovy.greeting={greeting.word},{some.name}
 groovy.greeting.with.smile={groovy.greeting} :)
 groovy.greeting.with.missing=Hello,{none} {0}
 groovy.greeting.with.escapes=Hello,{{some.name}}
+groovy.greeting.with.escapes2=Hello, curly brace {{}}
 property.character=a
 property.character.invalid=abc
 property.byte=1

http://git-wip-us.apache.org/repos/asf/groovy/blob/187617ea/src/test/groovy/util/GPropertiesTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/util/GPropertiesTest.groovy b/src/test/groovy/util/GPropertiesTest.groovy
index 5e84d54..0d8b944 100644
--- a/src/test/groovy/util/GPropertiesTest.groovy
+++ b/src/test/groovy/util/GPropertiesTest.groovy
@@ -79,6 +79,13 @@ class GPropertiesTest extends GroovyTestCase {
         assert 'Hello,{some.name}' == gp.getProperty('groovy.greeting.with.escapes')
     }
 
+    void testEscape2() {
+        def gp = new GProperties()
+        gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))
+
+        assert 'Hello, curly brace {}' == gp.getProperty('groovy.greeting.with.escapes2')
+    }
+
     void testGetCharacter() {
         def gp = new GProperties()
         gp.load(GPropertiesTest.getResourceAsStream('/groovy/util/gproperties.properties'))


Mime
View raw message