Repository: incubator-groovy Updated Branches: refs/heads/master a53bf0116 -> 5b2625998
GROOVY-7338: URL getText(requestProperties) Map now accepts a GString (Closes #19) Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/5b262599 Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/5b262599 Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/5b262599 Branch: refs/heads/master Commit: 5b26259988e395270aa4bb8512a9bfe5208d6c32 Parents: a53bf01 Author: Esteban <egi...@gmail.com> Authored: Mon May 18 23:15:49 2015 -0700 Committer: Paul King <pa...@asert.com.au> Committed: Tue May 19 20:53:31 2015 +1000 ---------------------------------------------------------------------- .../org/codehaus/groovy/runtime/ResourceGroovyMethods.java | 6 +++--- src/test/org/codehaus/groovy/runtime/URLGetBytesTest.groovy | 5 +++++ src/test/org/codehaus/groovy/runtime/URLGetTextTest.groovy | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/5b262599/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java ---------------------------------------------------------------------- diff --git a/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java b/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java index ce49168..909e112 100644 --- a/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java +++ b/src/main/org/codehaus/groovy/runtime/ResourceGroovyMethods.java @@ -2047,9 +2047,9 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport { } if (parameters.containsKey("requestProperties")) { @SuppressWarnings("unchecked") - Map<String, String> properties = (Map<String, String>) parameters.get("requestProperties"); - for (Map.Entry<String, String> entry : properties.entrySet()) { - connection.setRequestProperty(entry.getKey(), entry.getValue()); + Map<String, CharSequence> properties = (Map<String, CharSequence>) parameters.get("requestProperties"); + for (Map.Entry<String, CharSequence> entry : properties.entrySet()) { + connection.setRequestProperty(entry.getKey(), entry.getValue().toString()); } } http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/5b262599/src/test/org/codehaus/groovy/runtime/URLGetBytesTest.groovy ---------------------------------------------------------------------- diff --git a/src/test/org/codehaus/groovy/runtime/URLGetBytesTest.groovy b/src/test/org/codehaus/groovy/runtime/URLGetBytesTest.groovy index afb383d..e7a11ea 100644 --- a/src/test/org/codehaus/groovy/runtime/URLGetBytesTest.groovy +++ b/src/test/org/codehaus/groovy/runtime/URLGetBytesTest.groovy @@ -52,6 +52,11 @@ class URLGetBytesTest extends GroovyTestCase { assert url.getBytes(useCaches:true, requestProperties:[a:'b']) == 'Groovy cached a:b'.bytes assert url.getBytes() == url.getBytes((Map)null) + + assert url.getBytes(requestProperties: [a:"b"]) == "Groovy a:b".bytes + + def val = 'b' + assert url.getBytes(requestProperties: [a:"$val"]) == "Groovy a:b".bytes } private static class DummyURLConnection extends URLConnection { http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/5b262599/src/test/org/codehaus/groovy/runtime/URLGetTextTest.groovy ---------------------------------------------------------------------- diff --git a/src/test/org/codehaus/groovy/runtime/URLGetTextTest.groovy b/src/test/org/codehaus/groovy/runtime/URLGetTextTest.groovy index 31ba0c8..2daa3a4 100644 --- a/src/test/org/codehaus/groovy/runtime/URLGetTextTest.groovy +++ b/src/test/org/codehaus/groovy/runtime/URLGetTextTest.groovy @@ -60,7 +60,9 @@ class URLGetTextTest extends GroovyTestCase { assert url.getText() == url.getText() assert url.getText() == url.getText((Map)null) - + + def val = 'b' + assert url.getText(requestProperties: [a:"$val"]) == "Groovy a:b" } private static class DummyURLConnection extends URLConnection {