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

Strange HTML behaviour when viewing <div> enclosed within <a> tag using 'log in as'

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.4.6, 5.0
    • HTML and CSS
    • MOODLE_404_STABLE, MOODLE_500_STABLE

      Summary:

      When using 'Log in as' to view the Site home (at least this is the extend to where I've tested it), if there is custom HTML content embedded in the section summary where a <div> is enclosed within an <a>, the resulting HTML after using 'Log in as' is strange and different to when actually logged in with an account using username/password. <a> tags are duplicated in seemingly random places in the resulting HTML..

      This can be replicated in sandbox.moodledemo.net

      Steps to replicate:

      1. Access the site home page as a Site administrator

      2. Turn editing on and click the cog wheel to edit the section summary

      3. In the Description box, click View>Source code

      4. Paste the following HTML: 

      <a href="https://sandbox.moodledemo.net/course/index.php?categoryid=1"><img
          src="https://docs.moodle.org/skin/img/moodle_logo_tm.svg">
        <div class="testdiv"> </div>
      </a> 

      5. Save changes

      6. Right click the image and inspect element in browser - Observe all child elements underneath the <div class="no-overflow"> element (should two levels above the image link)

      7. Go to Site administration>Users>Browse list of users

      8. Click the name of a user in the list and click 'Log in as'

      9. Navigate back to the site home

      10. Repeat step 6

      Observed behaviour:

      Logged in normally the resulting HTML element is exactly what was entered into the section summary

      <div class="no-overflow"><a href="https://sandbox.moodledemo.net/course/index.php?categoryid=1"><img src="https://docs.moodle.org/skin/img/moodle_logo_tm.svg">
      <div class="testdiv">&nbsp;</div>
      </a></div> 

      Using 'Log in as' the resulting HTML element has duplicated the link (<a>) element multiple times in different locations:

      <div class="no-overflow"><a href="https://sandbox.moodledemo.net/course/index.php?categoryid=1">Here is some link content
      </a><div class="testdiv"><a href="https://sandbox.moodledemo.net/course/index.php?categoryid=1">Here is some div content</a></div><a href="https://sandbox.moodledemo.net/course/index.php?categoryid=1">
      </a></div> 

      Expected behaviour:

      The HTML appears the same regardless of whether logged in normally or using "log in as". There are no scripts being run here so there should be no effect on the HTML.

       

      Other notes:

      This came about as a result of trying to create a custom HTML grid in the Site home. While it works perfectly fine when using a regular login for any user, Log in as was displaying the grid broken. After distilling the problem down and stripping it down to the minimum required for replication, I determined it is the <div> nested inside the <a> that will result in the issue. While it isn't immediately visible in this case (beyond inspecting the element), under certain conditions like the grid I mentioned and combined with custom CSS classes, it can have quite a severe impact on the display of custom HTML.

            Unassigned Unassigned
            prankin Phillip Rankin
            Votes:
            4 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:

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