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

mod_url: Error makes course/view.php unreachable if an invalid URL is saved

XMLWordPrintable

    • MOODLE_311_STABLE, MOODLE_400_STABLE
    • MOODLE_310_STABLE, MOODLE_311_STABLE
    • MDL-73195-master
    • Hide
      1. Log in as admin and go to a course.
      2. Add a URL activity to a course, for example https:///duckduckgo.com
      3. Make sure you don't get any errors.
      4. Purge caches and go to course page.
      5. Make sure you are able to see the course content.
      Show
      Log in as admin and go to a course. Add a URL activity to a course, for example https:///duckduckgo.com Make sure you don't get any errors. Purge caches and go to course page. Make sure you are able to see the course content.
    • 1
    • HQ Team International CIH2-212

      The usage of moodle_url in the function url_guess_icon of mod/url/locallib.php that was introduced with MDL-39324 causes in some circumstances an error causing course/view.php not to be reachable anymore.

      Steps to reproduce the problem in the branch MOODLE_311_STABLE release 3.11.4, theme boost:

      • add a mod url to a course with an external url, for example https://mypage.com. The display type is not relevant.
      • edit the activity changing the external url so that the php function parse_url will return false, for example adding a third / after the protocol: https:///mypage.com and save (notice that at the present, trying to add the problematic url straight away will not work, but it was not so in the past).
      • purge all caches and visit course/view.php.
      • confirm that one obtains this error and stack trace:

      Error
      Invalid URL
      Debug info:
      Error code: invalidurl
      Stack trace:
      line 362 of /lib/weblib.php: moodle_exception thrown
      line 574 of /mod/url/locallib.php: call to moodle_url->__construct()
      line 223 of /mod/url/lib.php: call to url_guess_icon()
      line 477 of /course/lib.php: call to url_get_coursemodule_info()
      line 670 of /lib/modinfolib.php: call to get_array_of_activities()
      line 462 of /lib/modinfolib.php: call to course_modinfo::inner_build_course_cache()
      line 417 of /lib/modinfolib.php: call to course_modinfo->__construct()
      line 2204 of /lib/modinfolib.php: call to course_modinfo::instance()
      line 2050 of /lib/navigationlib.php: call to get_fast_modinfo()
      line 2114 of /lib/navigationlib.php: call to global_navigation->generate_sections_and_activities()
      line 502 of /course/format/lib.php: call to global_navigation->load_generic_course_sections()
      line 168 of /course/format/topics/lib.php: call to format_base->extend_course_navigation()
      line 2029 of /lib/navigationlib.php: call to format_topics->extend_course_navigation()
      line 1395 of /lib/navigationlib.php: call to global_navigation->load_course_sections()
      line 3503 of /lib/navigationlib.php: call to global_navigation->initialise()
      line 3548 of /lib/navigationlib.php: call to navbar->has_items()
      line 4566 of /lib/outputrenderers.php: call to navbar->get_items()
      line 44 of /theme/boost/layout/columns2.php: call to core_renderer->region_main_settings_menu()
      line 1396 of /lib/outputrenderers.php: call to include()
      line 1326 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()
      line 246 of /course/edit.php: call to core_renderer->header()
       

      The reason appears to be that the function url_guess_icon is called when executing course_modinfo::inner_build_course_cache(). This happens for example when loading course/view.php after having emptied all caches. When the url is such that the php function parse_url returns false (for example in the case that the url starts with http:///) an exception is thrown in the constructor of moodle_url and this causes the course to be completely inaccessible.

       
      Notice that because of the guard if (substr_count($fullurl, '/') < 3 or substr($fullurl, -1) === '/') in line 568 of url_guess_icon in /mod/url/locallib.php nothing bad will happen, if the url ends with a / - in our example https:///mypage.com/ will not cause any trouble.

       
      What happened in our site was, that courses created in the past with malformed external urls in some mod_url activities where not accessible anymore after updating.
       

       

        1. MDL-73195_master_Step 3.png
          MDL-73195_master_Step 3.png
          43 kB
        2. MDL-73195_master_Step 5.png
          MDL-73195_master_Step 5.png
          68 kB
        3. MDL-73195_v310_Step 3.png
          MDL-73195_v310_Step 3.png
          39 kB
        4. MDL-73195_v310_Step 5.png
          MDL-73195_v310_Step 5.png
          87 kB
        5. MDL-73195_v311_Step 3.png
          MDL-73195_v311_Step 3.png
          41 kB
        6. MDL-73195_v311_Step 5.png
          MDL-73195_v311_Step 5.png
          86 kB
        7. MDL-73195 invalid url error.png
          MDL-73195 invalid url error.png
          96 kB

            lameze Simey Lameze
            ManeggiaP Paola Maneggia
            Michael Hawkins Michael Hawkins
            Andrew Lyons Andrew Lyons
            Angelia Dela Cruz Angelia Dela Cruz
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:

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

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.