Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript error on course section page when edit mode enabled #40

Open
leonstr opened this issue Aug 15, 2024 · 2 comments
Open

JavaScript error on course section page when edit mode enabled #40

leonstr opened this issue Aug 15, 2024 · 2 comments

Comments

@leonstr
Copy link

leonstr commented Aug 15, 2024

On Moodle 4.4 if you:

  1. create a course and enrol and editing teacher;
  2. log in as the editing teacher;
  3. go to the course page;
  4. click on a section title to go to a course section page (course/section.php?id=<ID>);
  5. enable editing mode,

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.

@leonstr
Copy link
Author

leonstr commented Aug 15, 2024

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.

@leonstr leonstr mentioned this issue Aug 15, 2024
@leonstr
Copy link
Author

leonstr commented Aug 15, 2024

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)))."'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant