Groovy
  1. Groovy
  2. GROOVY-4362

Node.text() returns empty string for non-String or Collection values

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.7.4
    • Fix Version/s: 1.8.6, 2.0-beta-3
    • Component/s: XML Processing
    • Labels:
      None

      Description

      The text() method of groovy.util.Node is coded to return an empty string ("") if you set a value that is not a string or a collection. This means if you set the value as a number you get back an empty string.

      Should this method return value.toString() in all cases where value is not a collection?

      For instance -

      def xml = "<root><node1/></root>"
      def root = new XmlParser().parseText(xml)
      root.node1[0].replaceNode() {
          node2() {
             childN(5)
             childS('5')
          }
      }
      
      assert root.node2[0].childS[0].text() == '5'
      assert root.node2[0].childN[0].text() == '5'
      

        Activity

        jspeakman created issue -
        Hide
        Paul King added a comment -

        add code tags

        Show
        Paul King added a comment - add code tags
        Paul King made changes -
        Field Original Value New Value
        Description The text() method of groovy.util.Node is coded to return an empty string ("") if you set a value that is not a string or a collection. This means if you set the value as a number you get back an empty string.

        Should this method return value.toString() in all cases where value is not a collection?

        For instance -

        def xml = "<root><node1/></root>"
        def root = new XmlParser().parseText(xml)
        root.node1[0].replaceNode() {
            node2() {
               childN(5)
               childS('5')
            }
        }

        assert root.node2[0].childS[0].text() == '5'
        assert root.node2[0].childN[0].text() == '5'
        The text() method of groovy.util.Node is coded to return an empty string ("") if you set a value that is not a string or a collection. This means if you set the value as a number you get back an empty string.

        Should this method return value.toString() in all cases where value is not a collection?

        For instance -
        {code}
        def xml = "<root><node1/></root>"
        def root = new XmlParser().parseText(xml)
        root.node1[0].replaceNode() {
            node2() {
               childN(5)
               childS('5')
            }
        }

        assert root.node2[0].childS[0].text() == '5'
        assert root.node2[0].childN[0].text() == '5'
        {code}
        Hide
        Paul King added a comment -

        I believe this was fixed as a side-effect of GROOVY-5257. At least the fix I was going to apply for this issue was already applied even though it doesn't seem specifically related to GROOVY-5257. Perhaps I was working on both issues and committed both changes back then or perhaps it was required because of the tests required for that issue. Anyway, please report any problems if you still observe them.

        Show
        Paul King added a comment - I believe this was fixed as a side-effect of GROOVY-5257 . At least the fix I was going to apply for this issue was already applied even though it doesn't seem specifically related to GROOVY-5257 . Perhaps I was working on both issues and committed both changes back then or perhaps it was required because of the tests required for that issue. Anyway, please report any problems if you still observe them.
        Paul King made changes -
        Fix Version/s 2.0-beta-3 [ 18244 ]
        Assignee Paul King [ paulk ]
        Status Open [ 1 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]
        Fix Version/s 1.8.6 [ 18245 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12733303 ] Default workflow, editable Closed status [ 12745128 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12970912 ] Default workflow, editable Closed status [ 12978665 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Closed Closed
        598d 14h 25m 1 Paul King 01/Apr/12 22:41

          People

          • Assignee:
            Paul King
            Reporter:
            jspeakman
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development