Uploaded image for project: 'phpBB3'
  1. phpBB3
  2. PHPBB3-11435

Extension template files curly braces bug

    Details

    • Type: Bug
    • Status: Unverified Fix
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 3.1.0-dev
    • Fix Version/s: 3.1.0-a1
    • Component/s: Extensions
    • Labels:
      None
    • Environment:
      PHP 5.3.6, phpBB 3.1-dev, Safari 6.0.2

      Description

      In an extension with template event files that use language vars, the language vars are injected with a newline immediately after each lang var.

      This breaks javascript when js code uses language vars in it's code, such as in strings. It can also potentially break html.

      Example: an extension template file (i.e.: overall_footer_after.html) contains:

      <script type="text/javascript">
       
      var text = "{LA_FORUM_INDEX}";
       
      </script>
       
      <div>{L_FORUM_INDEX}</div>
      

      This is rendered by phpBB in HTML as:

      <script type="text/javascript">
       
      var text = "Board index
      ";
       
      </script>
       
      <div>Board index
      </div>
      

      Note the new line added after the language var! This happens for both LA_ and L_ language vars anywhere they may be used in extension template files. It also does not matter if the extension's template is using core phpBB lang vars, and/or its own. It happens in all cases with extension templates.

      Update: This isn't limited to language vars. It's any where a curly brace variable is used in an event template file, i.e.:

      <a href="{U_VIEW_TOPIC}" class="topictitle">{TOPIC_TITLE}</a> 
      

      becomes:

      <a href="./viewtopic.php?f=2&amp;t=7
      " class="topictitle">My Great Topic
      </a>  
      

      or

      <dl class="icon {TOPIC_IMG_STYLE}">
      

      becomes:

      <dl class="icon topic_read
      ">
      

      Notice that every } closing curly brace creates a newline in the html output

      I also examined a cached file, to see how the php is being rendered by the template engine, and found the previous example to look something like this:

      <dl class="icon <?php echo (isset($_row_val['TOPIC_IMG_STYLE'])) ? $_row_val['TOPIC_IMG_STYLE'] : ''; ?>
       
      ">
      

      As you can see, actually two newlines are added between the closing php tag and the double quote from the template!

      So it is like the template engine is adding ?>\n\n for every closing curly brace.

        Issue Links

          Activity

          Hide
          EXreaction EXreaction [X] (Inactive) added a comment -
          Show
          EXreaction EXreaction [X] (Inactive) added a comment - I created some tests: https://github.com/phpbb/phpbb3/pull/1372
          Hide
          EXreaction EXreaction [X] (Inactive) added a comment -

          The cause of the difference is due to template/filter.php line 253:
          $data = str_replace('/**/?>', "?>\n", $data);

          But that code cannot just be removed because it screws other things up.

          I think the problem that's coming up is that cleanup is being run twice on event code and just once on regular template code, so something needs to be done to stop the cleanup being run twice on the event output.

          Show
          EXreaction EXreaction [X] (Inactive) added a comment - The cause of the difference is due to template/filter.php line 253: $data = str_replace('/**/?>', "?>\n", $data); But that code cannot just be removed because it screws other things up. I think the problem that's coming up is that cleanup is being run twice on event code and just once on regular template code, so something needs to be done to stop the cleanup being run twice on the event output.
          Hide
          VSE Matt Friedman added a comment -

          Also another distinction: extensions templates that are used in an extension controller (using the helper->render function) are not affected by this. It only appears to be an issue for extension templates included via the <!-- EVENT --> tag

          Show
          VSE Matt Friedman added a comment - Also another distinction: extensions templates that are used in an extension controller (using the helper->render function) are not affected by this. It only appears to be an issue for extension templates included via the <!-- EVENT --> tag
          Hide
          EXreaction EXreaction [X] (Inactive) added a comment -

          Oleg, would you mind taking a look at this?

          Show
          EXreaction EXreaction [X] (Inactive) added a comment - Oleg, would you mind taking a look at this?
          Show
          bantu Andreas Fischer added a comment - Merged https://github.com/phpbb/phpbb3/pull/1381

            People

            • Assignee:
              EXreaction EXreaction [X] (Inactive)
              Reporter:
              VSE Matt Friedman
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development