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

[PATCH] SimpleTemplateEngine line number is off by one

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.8.3, 1.9-beta-4
    • Component/s: None
    • Labels:
      None
    • Flags:
      Patch

      Description

      Line number reported from scripts compiled by SimpleTemplateEngine is off by one because it generates an extra new line that's not found in the original source file. Patch attached.

      1. DIFF
        0.7 kB
        Kohsuke Kawaguchi

        Activity

        Hide
        Guillaume Guillaume Delcroix added a comment -

        Good idea too here!

        Show
        Guillaume Guillaume Delcroix added a comment - Good idea too here!
        Hide
        blackdrag Jochen Theodorou added a comment -

        looks like a good idea to me

        Show
        blackdrag Jochen Theodorou added a comment - looks like a good idea to me
        Hide
        roshandawrani Roshan Dawrani added a comment -

        Good. There shouldn't probably be, but will just wait for a little bit to see if other devs see any potential impact.

        Show
        roshandawrani Roshan Dawrani added a comment - Good. There shouldn't probably be, but will just wait for a little bit to see if other devs see any potential impact.
        Hide
        kohsuke Kohsuke Kawaguchi added a comment -

        I don't have any objection at all (in fact as far as I'm concerned, I couldn't care less about this "generated by" comment.)

        Show
        kohsuke Kohsuke Kawaguchi added a comment - I don't have any objection at all (in fact as far as I'm concerned, I couldn't care less about this "generated by" comment.)
        Hide
        roshandawrani Roshan Dawrani added a comment -

        Thanks for the patch. A slight improvement suggested below.

        If we currently have script generated as a), with the patch it looks like b)

        a)

        -- script source --
        /* Generated by SimpleTemplateEngine */
        out.print("""Hello \"$firstname\",
        Nice to meet you in """); print city ;
        out.print("""""");
        
        -- script end --
        

        b)

        -- script source --
        /* Generated by SimpleTemplateEngine */out.print("""Hello \"$firstname\",
        Nice to meet you in """); print city ;
        out.print("""""");
        
        -- script end --
        

        With slightld modified patch, it looks like c)

                 private void startScript(StringWriter sw) {
        -            sw.write("/* Generated by SimpleTemplateEngine */\n");
                     sw.write("out.print(\"\"\"");
                 }
         
                 private void endScript(StringWriter sw) {
        -            sw.write("\"\"\");\n");
        +            sw.write("\"\"\");\n\n/* Generated by SimpleTemplateEngine */");
                 }
        

        Suggested new output that preserves the line numbers of the original script, but reads slightly better

        -- script source --
        out.print("""Hello \"$firstname\",
        Nice to meet you in """); print city ;
        out.print("""""");
        
        /* Generated by SimpleTemplateEngine */
        -- script end --
        
        Show
        roshandawrani Roshan Dawrani added a comment - Thanks for the patch. A slight improvement suggested below. If we currently have script generated as a), with the patch it looks like b) a) -- script source -- /* Generated by SimpleTemplateEngine */ out.print("""Hello \"$firstname\", Nice to meet you in """); print city ; out.print(""""""); -- script end -- b) -- script source -- /* Generated by SimpleTemplateEngine */out.print("""Hello \"$firstname\", Nice to meet you in """); print city ; out.print(""""""); -- script end -- With slightld modified patch, it looks like c) private void startScript(StringWriter sw) { - sw.write( "/* Generated by SimpleTemplateEngine */\n" ); sw.write( "out.print(\" \ "\" "); } private void endScript(StringWriter sw) { - sw.write( "\" \ "\" );\n"); + sw.write( "\" \ "\" );\n\n/* Generated by SimpleTemplateEngine */"); } Suggested new output that preserves the line numbers of the original script, but reads slightly better -- script source -- out.print("""Hello \"$firstname\", Nice to meet you in """); print city ; out.print(""""""); /* Generated by SimpleTemplateEngine */ -- script end --

          People

          • Assignee:
            roshandawrani Roshan Dawrani
            Reporter:
            kohsuke Kohsuke Kawaguchi
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development