Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-69553

Template loader does not handle multi-line string declarations well

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.7.7, 3.8.4, 3.9.1
    • 3.8.6, 3.9.3
    • Forum, Themes
    • MOODLE_37_STABLE, MOODLE_38_STABLE, MOODLE_39_STABLE
    • MOODLE_38_STABLE, MOODLE_39_STABLE
    • MDL-69553-m39
    • Hide

      Turn off developer debugging or displaying debugging messages to screen to hide the problem

      Show
      Turn off developer debugging or displaying debugging messages to screen to hide the problem
    • Hide

      Automatic test

      The issue is covered by PHP Unit Tests.

      Assumptions

      • A course containing a forum with the following settings:
        • Whole forum grading > Grade: Point
      • The forum contains at least one post

      Manual Test

      1. Login as the site admin user
      2. Navigate to Site administration > Development > Debugging
      3. Set Debug messages to DEVELOPER
      4. Check Display debug messages
      5. Navigate to the forum
      6. Press the Grade users button
      7. Verify that no popup errors are displayed
      8. Verify that the forum posts are displayed
      Show
      Automatic test The issue is covered by PHP Unit Tests. Assumptions A course containing a forum with the following settings: Whole forum grading > Grade: Point The forum contains at least one post Manual Test Login as the site admin user Navigate to Site administration > Development > Debugging Set Debug messages to DEVELOPER Check Display debug messages Navigate to the forum Press the Grade users button Verify that no popup errors are displayed Verify that the forum posts are displayed

    Description

      With developer debugging on templates that have string declarations spread over multiple lines fail to load correctly.

      Steps to reproduce

      Assumptions

      1. A forum with at least one post with the following settings required:
        1. Whole forum grading > Grade: Point
      2. Developer debug is turned on
      3. Display debug messages is on

      Steps

      1. Navigate to the forum
      2. Press the Grade users button

      At this point there will be an TypeError exception with a message like Cannot read property 'stack' on 'Internal Server Error'

      Looking at the Network traffic for the page you will be able to see that a call to the core_output_load_template web service returned:

      Debugging: Invalid get_string() identifier: '' or component 'core'. Perhaps you are missing $string[''] = ''; in lang/en/core.php? in 
      * line 353 of \lib\classes\string_manager_standard.php: call to debugging()
      * line 207 of \lib\classes\output\mustache_template_source_loader.php: call to core_string_manager_standard->get_string()
      * line 182 of \lib\classes\output\mustache_template_source_loader.php: call to core\output\mustache_template_source_loader->core\output\{closure}()
      * line 210 of \lib\classes\output\mustache_template_source_loader.php: call to core\output\mustache_template_source_loader->core\output\{closure}()
      * line 232 of \lib\classes\output\mustache_template_source_loader.php: call to core\output\mustache_template_source_loader->load_with_dependencies()
      * line 182 of \lib\classes\output\mustache_template_source_loader.php: call to core\output\mustache_template_source_loader->core\output\{closure}()
      * line 254 of \lib\classes\output\mustache_template_source_loader.php: call to core\output\mustache_template_source_loader->core\output\{closure}()
      * line 152 of \lib\classes\output\external.php: call to core\output\mustache_template_source_loader->load_with_dependencies()
      * line 261 of \lib\externallib.php: call to core\output\external::load_template_with_dependencies()
      * line 81 of \lib\ajax\service.php: call to external_api::call_external_function()
      * line 33 of \lib\ajax\service-nologin.php: call to require_once()
      

      I managed to track it to the a multiline string declaration

      It appears to be because the preloader assumes that the next token will be the string name, when in this case the next token is a new line; the actual string identifiers are in fact part of the +2 token.

      So the pre-loader attempts to load a string with an identifier of '' and a components of 'core' which fails.

      The following scenarios would all fail

      Correct string name; wrong component (will always be core):

      {{#str}} string,
      component {{/str}}
      

      Will not find string or component correctly:

      {{#str}} 
      string, component 
      {{/str}}
      

      {{#str}} 
      string,
      component 
      {{/str}}
      

      Attachments

        Issue Links

          Activity

            People

              nmagill Neill Magill
              nmagill Neill Magill
              Ferran Recio Ferran Recio
              Sara Arjona (@sarjona) Sara Arjona (@sarjona)
              CiBoT CiBoT
              Adrian Greeve, Ilya Tregubov, Kevin Percy, Mathew May, Mihail Geshoski, Shamim Rezaie, Huong Nguyen, Bas Brands, Mathew May
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                9/Nov/20

                Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 3 hours, 45 minutes
                  3h 45m