Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7338

URL getText(requestProperties) Map doesn't accept a GString

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.4.4
    • Component/s: None
    • Labels:
      None

      Description

      Many times you construct a header with multiple values then pass it to requestProperties map. It would be more groovy if it accepted a GString instead of having to cast it to a String

      # Less Groovy - 
      url.getText(requestProperties:[Authentication:"Basic $auth".toString()]) == 'Groovy a:b'
      # More Groovy - 
       url.getText(requestProperties:[Authentication:"Basic $auth"]) == 'Groovy a:b'
      

      Exception -

      :test
      
      org.codehaus.groovy.runtime.URLGetTextTest > testGetTextFromURLWithParameters FAILED
          java.lang.ClassCastException: org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String
              at org.codehaus.groovy.runtime.ResourceGroovyMethods.configuredInputStream(ResourceGroovyMethods.java:2026)
              at org.codehaus.groovy.runtime.ResourceGroovyMethods.newReader(ResourceGroovyMethods.java:2132)
              at org.codehaus.groovy.runtime.ResourceGroovyMethods.getText(ResourceGroovyMethods.java:665)
              at org.codehaus.groovy.runtime.ResourceGroovyMethods.getText(ResourceGroovyMethods.java:633)
              at org.codehaus.groovy.runtime.dgm$965.invoke(Unknown Source)
              at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)
              at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
              at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
              at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
              at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:122)
              at org.codehaus.groovy.runtime.URLGetTextTest.testGetTextFromURLWithParameters(URLGetTextTest.groovy:57)
      
      1 test completed, 1 failed
      :test FAILED
      

      Test -

      diff --git a/src/test/org/codehaus/groovy/runtime/URLGetTextTest.groovy b/src/test/org/codehaus/groovy/runtime/URLGetTextTest.groovy
      index 8a037e5..29a5f59 100644
      --- a/src/test/org/codehaus/groovy/runtime/URLGetTextTest.groovy
      +++ b/src/test/org/codehaus/groovy/runtime/URLGetTextTest.groovy
      @@ -53,6 +53,9 @@ class URLGetTextTest extends GroovyTestCase {
       
               assert url.getText(requestProperties:[a:'b']) == 'Groovy a:b'
       
      +        def b = "b"
      +        assert url.getText(requestProperties:[a:"$b"]) == 'Groovy a:b'
      +
               assert url.getText(useCaches:true, requestProperties:[a:'b']) == 'Groovy cached a:b'
       
               assert url.getText() == url.getText()
      

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              erichelgeson Eric Helgeson
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: