Open leonstr opened 2 months ago
For Google Analytics local_analytics populates the 'title' property with format_string($PAGE->heading)
. With edit mode enabled for a course section page $PAGE->heading
is:
<div data-for="section_title"><span class="inplaceeditable inplaceeditable-text" data-inplaceeditable="1" data-component="format_topics" data-itemtype="sectionnamenl" data-itemid="3"
data-value="" data-editlabel="New name for section New section" data-type="text" data-options="">
<a href="#" class="quickeditlink aalink" data-inplaceeditablelink="1" title="Edit section name">
New section
<span class="quickediticon visibleifjs icon-size-3">
<i class="icon fa fa-pencil fa-fw " title="Edit section name" role="img" aria-label="Edit section name"></i>
</span>
</a>
</span></div>
format_string()
strips the tags but leaves the line breaks making this:
New section
Obviously wrapping the above in single quotes is not a valid JavaScript string value, thus the syntax error.
PR with proposed fix added. An alternative approach would be to use trim()
to remove $PAGE->heading
's newlines by changing classes/api/guniversal.php
line 55 to:
'title' : '".addslashes(trim(format_string($PAGE->heading)))."'
On Moodle 4.4 if you:
course/section.php?id=<ID>
);then the page is broken, for example, the left-hand navigation drawer does not load and the user menu in the top right does not open when clicked. The browser console shows '' string literal contains an unescaped line break.
Moodle 4.4.2 (Build: 20240812) with local_analytics 2017032702.