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

URL activity links contain double encoded &, loss of display specific attributes

XMLWordPrintable

    • MOODLE_401_STABLE
    • MOODLE_401_STABLE, MOODLE_402_STABLE
    • MDL-78895-401
    • Hide
      1. Log in as admin
      2. Navigate to Profile from user menu
      3. Press Miscellaneous > Forum discussions and copy the URL - it'll be something like (the relevant portion is the &mode=... parameter):

        http://localhost:8000/mod/forum/user.php?id=2&mode=discussions
        

      4. Create a course
      5. Add a URL activity
        • Name: My discussions
        • URL: <COPIED-URL>
      6. Press Save and display
      7. Press the Click on My discussions to open the resource. link
      8. Confirm the ampersand in the URL isn't double encoded (you should see the message You haven't started any discussions yet)
      9. Press Back in your browser to go back to the view page
      10. Press Settings
      11. Set Appearance > Display to In popup
      12. Press Save and display
      13. Press the Click on My discussions to open the resource. link
      14. Confirm link opens in popup window
      15. Confirm the ampersand in the popup URL isn't double encoded (you should see the message You haven't started any discussions yet)
      16. Press Settings
      17. Set Appearance > Display to Embed
      18. Press Save and display
      19. Confirm the ampersand in the iframe URL isn't double encoded (you should see the message You haven't started any discussions yet)
      Show
      Log in as admin Navigate to Profile from user menu Press Miscellaneous > Forum discussions and copy the URL - it'll be something like (the relevant portion is the &mode=... parameter): http://localhost:8000/mod/forum/user.php?id=2&mode=discussions Create a course Add a URL activity Name: My discussions URL: <COPIED-URL> Press Save and display Press the Click on My discussions to open the resource. link Confirm the ampersand in the URL isn't double encoded (you should see the message You haven't started any discussions yet ) Press Back in your browser to go back to the view page Press Settings Set Appearance > Display to In popup Press Save and display Press the Click on My discussions to open the resource. link Confirm link opens in popup window Confirm the ampersand in the popup URL isn't double encoded (you should see the message You haven't started any discussions yet ) Press Settings Set Appearance > Display to Embed Press Save and display Confirm the ampersand in the iframe URL isn't double encoded (you should see the message You haven't started any discussions yet )

      Summary:

      The changes from https://github.com/moodle/moodle/commit/8d8af19af0fd3560ecbefed9db44649783e79837 (MDL-78452) have caused a couple of regressions:

      1. Ampersands are double encoded because of this - same workaround as here required
      2. The previous $extra attributes have been lost, used for displaying the link in a popup or new window

      Original report

      I recently upgraded from 3.9 to 4.1.4+ (Build: 20230714) - update, the 4.1.5 is the same

      Course format/Course layout is one section per page.
      In course I had activity/resource URL (external, though it is not) referring to the certain section of my course. Something like https://mymoodle.site/course/view.php?id=9&section=3
      The same link I added to the Description part. When checking the HTML code, it seems the & character is replaced with "& a m p ;" sequence.
      The result is, that when displaying this activity/resource "page" (https://mymoodle.site/mod/url/view.php?id=963&forceview=1), the link from description works fine, but link from field of External URL displays as https://mymoodle.site/course/view.php?id=903& a m p ;section=6 and takes me only on the course (overview/front) page https://mymoodle.site/course/view.php?id=903
      (I added spaces above)
      It worked in 3.9., it works in 4.1.2+ (Build: 20230418). Searching  moodle.git, 4.1.3 is the same as 4.1.2.
      This behaviour affects links saved before upgrade and new ones as well.
      Change between versions is in /moodle/mod/url/locallib.php (lines 280 and 301).
      I tried to replace the /moodle/mod/url/locallib.php in 4.1.4 with file from 4.1.2 (I have test environment). I see it works well. The working one displays url, the corrupted one displays name (looks nicer, but is not working). But it is not a solution.

      Update: Done some more tests. When I reported bug, I had Automatic Appearance. Now I have tested each possible appearance (Embed, Open, In pop-up) and Embed, and only Embed works with url-s containing "&". It is because it uses content of variable $fullurl. "Open" uses "html_writer::link" which somehow does no good when used with "print_string".

      Until it is resolved, I replace line 280 in /moodle/mod/url/locallib.php:

      print_string('clicktoopen', $fullurl , html_writer::link($fullurl, format_string($cm->name)));

      with:

      print_string('clicktoopen', 'url', "<a href=\"$fullurl\" $extra>$cm->name</a>");

        1. MDL-78895.png
          MDL-78895.png
          730 kB
        2. url_error.png
          url_error.png
          194 kB
        3. url_error-1.png
          url_error-1.png
          194 kB

            pholden Paul Holden
            Koperdakova Eva
            Neill Magill Neill Magill
            Shamim Rezaie Shamim Rezaie
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            4 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved:

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

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