HTML block displays differently for non-site admin users

HTML block displays differently for non-site admin users

by Jeff Columb -
Number of replies: 3

I have an HTML block on the /my/index.php page of a site. It is being used by the client to link to various courses and course search topics for their students to quickly find relevant courses; they are routinely editing it to keep it up to date with their current curricula.

Recently on transitioning the site to a new moodle and php version, suddenly some elements are being completely removed when displayed for users that aren't site-admins. I've confirmed that the elements are being saved and exist, but when displayed they just aren't there. I have put as much relevant info below as possible. My apologies for the state of the code; I have swapped the urls and link text, everything else is as-is.

"DEV"(Working for users and site admins)
Moodle: 3.5.4 (Build: 20190114)
PHP: 7.2.14
Theme: Impressions (2017111300)

"LIVE" (Working for site admins only)
Moodle: 3.5.6+ (Build: 20190614)
PHP: 7.2.19
Theme: Impressions (2017111300)


Site admin inspect result: 
[
  <h4><b>Online Courses<br></b></h4>

  <ul class="list-group"><a href="https://my_website/course/search.php?search=Some+Search+Terms">

  </a><li class="list-group-item"><a href="https://my_website/course/search.php?search=Some+Search+Terms">Some Search Terms</a><br></li><a href="http://blank">

  </a><li class="list-group-item"><a href="https://my_website/course/view.php?id=173">This Course Name</a><br></li><a href="http://blank">

  </a><li class="list-group-item"><a href="https://my_website/course/view.php?id=329"><span><span>This Course Name<br></span></span></a></li><a href="http://blank">

  </a><li class="list-group-item"><a href="https://my_website/course/view.php?id=327"><span><span>This Course Name</span></span></a><a href="http://blank"><span><span><br></span></span></a></li></ul>
]

Any other user inspect result: 
[
  <h4><b>Online Courses<br></b></h4>

  <a href="https://my_website/course/search.php?search=Some+Search+Terms">

  </a>

  <a href="https://my_website/course/search.php?search=Some+Search+Terms">Some Search Terms</a>

  <br>

  <a href="http://blank">

  </a>

  <a href="https://my_website/course/view.php?id=173">This Course Name</a>

  <br>

  <a href="http://blank">

  </a>

  <a href="https://my_website/course/view.php?id=329"><span><span>This Course Name<br></span></span></a>

  <a href="https://my_website/course/view.php?id=327"><span><span>This Course Name</span></span></a>

  <a href="http://blank"><span><span><br></span></span></a>
]

As you may notice, the ul and li tags are just gone. I tried looking through the code and changed the theme just in case, but no such luck. At this point I don't know if it's a bug or I've developed tunnel vision and can't see something obvious.

I recently had this issue with a form tag being stripped, but was able to write my own block rather than using the HTML block. But, due to the user's routine editing of this block's content, I would rather use the already working HTML block instead of writing my own to do the same thing; and possibly encountering the same issue.

Thanks in advance.

Average of ratings: -
In reply to Jeff Columb

Re: HTML block displays differently for non-site admin users

by Anthony Rimmer -
Hi Jeff,

Is there a reason for the empty 'A' tags between each list item?

It might be worth stripping out all the extra parts and continuing from there:

<h4><b>Online Courses</b></h4><br>
<ul class="list-group">
  <li class="list-group-item"><a href="https://my_website/course/search.php?search=Some+Search+Terms">Some Search Terms</a></li>
  <li class="list-group-item"><a href="https://my_website/course/view.php?id=173">This Course Name</a></li>
  <li class="list-group-item"><a href="https://my_website/course/view.php?id=329">This Course Name</a></li>
  <li class="list-group-item"><a href="https://my_website/course/view.php?id=327">This Course Name</a></li>
</ul>

I hope this helps, 

Anthony

In reply to Anthony Rimmer

Re: HTML block displays differently for non-site admin users

by Jeff Columb -

Sorry for the late reply. Some other project became the priority so I've had to let this one stew for a bit.

Thank you for your advice, it turns out the problem was twofold. As you suggested stripping out the extra parts was indeed part of the solution.

So to summarize: There were three lists in this html block. The first two lists did not have a <ul> tag surrounding the <li> tags. The third list (Online courses) had the extra <a href="http://blank"> tags in between the <li> and <ul> tags as well as between each <li> tags.

I'm not sure why the list tags were stripped in both instances or why site admin users were unaffected; I did not know moodle or themes could strip tags entirely from the display. But resolving the issues in the client's code resolved the issues with the display.

Thank you Anthony,
Jeff C.

In reply to Jeff Columb

Re: HTML block displays differently for non-site admin users

by Anthony Rimmer -
Hi Jeff,

Glad you got sorted!

I'm still not sure why you'd see differences in views per user type. I can only imagine some sort of extra stripping done by Moodle to reduce questionable code for those with lesser rights - Maybe someone could expand further?

You may already know of it, but the W3 validator is a useful tool for quickly checking markup issues: https://validator.w3.org/

Kind regards,

Anthony