Arbit - project tracking

Dwoo

#28: Trailing Space after Comment Bug

Issue revisions

  • closed by Tim Oram at 2009-M-13 9:29
  • closed by Tim Oram at 2009-M-13 9:29
  • closed by Tim Oram at 2009-M-13 9:29
Type bug bug
State closed closed
Priority low low
Resolution fixed fixed
Assigned to Jordi Boggiano
Scheduled for 1.1.0
Affected versions
Affected components Core
Last change Friday 13 March 2009 09:29:52 UTC by Tim Oram

Also tested on the latest from trunk.

Summary: One or more white spaces on own line at end of template will cause template to not compile.

Expected Result: Template to compile

Actual Result: Errors Displayed

Errors Given: Warning: strpos() [function.strpos]: Offset not contained in string in Dwoo/Compiler.php on line 1273 Dwoo_Compilation_Exception: Compilation error at line 1 in "file:template.tpl" : Un-ended comment in Dwoo/Compiler.php on line 1275

Reduced test case is provided.

  • Jordi Boggiano at Friday 13 March 2009 09:41:29 UTC

    The possibilities of messing up parsing never cease to amaze me, thanks for the report, it's reproduced here and I will have a look. Typically something I don't notice since I strip all trailing whitespace on save.

  • Tim Oram at Friday 13 March 2009 09:59:04 UTC

    I think I may have tracked down the bug, though I don't completely understand what the code is doing. In the parse function of Compiler.php the $startpos variable is allowed to become a negative number by the trailing whitespace. I simple check to see if the $startpos variable is negative should fix this I would think.
    
    Adding the below check after line 1234 in version 1.1.0 should do the trick.
    <pre>
    if($startpos < 0){
    	$startpos = 0;
    }
    </pre>
    I think the only other way would be to keep track of the amount of tabs and spaces at the end of the file but I think this is a better solution.
  • Jordi Boggiano at Friday 13 March 2009 10:15:40 UTC

    Applied in changeset r258.

  • Jordi Boggiano at Friday 13 March 2009 10:19:29 UTC

    Your solution would have worked for your test, but I think it failed if you had something like " {* comment with space before *}n ", anyway it should all work now.