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

MarkupBuilder cant yield before first tag

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.8, 3.0.0-rc-2
    • 4.0.0-alpha-1, 3.0.5
    • XML Processing
    • None
    • Oracle Java 1.8.0_112, Windows 10 x64

    Description

      Trying to produce an HTML5 compliant !DOCTYPE before starting with the HTML-Elements. Without setting the private field 'state' to 2, the output does not show the yielded output.

      def html = new groovy.xml.MarkupBuilder(new PrintWriter(System.out))
      //html.state = 2
      html.mkp.yieldUnescaped("<!DOCTYPE html>\n")
      html.h1("Header")
      

      I suggest fixing this by changing the yield-Method to not check the state before doing the output, so that we see some output when the initial state is still 0:

      void yield(String value, boolean escaping) {
          if (state == 1) {
              state = 2;
              this.nodeIsEmpty = false;
              out.print(">");
          }
          // -- remove -- if (state == 2 || state == 3) {
          out.print(escaping ? escapeElementContent(value) : value);
          // -- remove -- }
      }
      

      Attachments

        Activity

          People

            daniel_sun Daniel Sun
            eddelplus Jochen Eddelbuettel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h