MDL-68722 atto_equation: fix for form elements with special characters
authorMatt Clarkson <mattc@catalyst.net.nz>
Fri, 23 Oct 2020 03:06:36 +0000 (16:06 +1300)
committerMatt Clarkson <mattc@catalyst.net.nz>
Tue, 27 Oct 2020 20:26:43 +0000 (09:26 +1300)
Element id's containing characters such as ':' would break the tab
selector in bootstrap.

This specifically affects the essay question type.

lib/editor/atto/plugins/equation/yui/build/moodle-atto_equation-button/moodle-atto_equation-button-debug.js
lib/editor/atto/plugins/equation/yui/build/moodle-atto_equation-button/moodle-atto_equation-button-min.js
lib/editor/atto/plugins/equation/yui/build/moodle-atto_equation-button/moodle-atto_equation-button.js
lib/editor/atto/plugins/equation/yui/src/button/js/button.js

index 1b4fdf4..9b92082 100644 (file)
Binary files a/lib/editor/atto/plugins/equation/yui/build/moodle-atto_equation-button/moodle-atto_equation-button-debug.js and b/lib/editor/atto/plugins/equation/yui/build/moodle-atto_equation-button/moodle-atto_equation-button-debug.js differ
index 8e720ff..4fb26eb 100644 (file)
Binary files a/lib/editor/atto/plugins/equation/yui/build/moodle-atto_equation-button/moodle-atto_equation-button-min.js and b/lib/editor/atto/plugins/equation/yui/build/moodle-atto_equation-button/moodle-atto_equation-button-min.js differ
index 9e38bd2..bd82437 100644 (file)
Binary files a/lib/editor/atto/plugins/equation/yui/build/moodle-atto_equation-button/moodle-atto_equation-button.js and b/lib/editor/atto/plugins/equation/yui/build/moodle-atto_equation-button/moodle-atto_equation-button.js differ
index 4c1cb08..00779ca 100644 (file)
@@ -74,6 +74,7 @@ var COMPONENTNAME = 'atto_equation',
                     '{{#each library}}' +
                         '<li  class="nav-item">' +
                             '<a class="nav-link" href="#{{../elementid}}_{{../CSS.LIBRARY_GROUP_PREFIX}}_{{@key}}" ' +
+                                ' data-target="#{{../elementidescaped}}_{{../CSS.LIBRARY_GROUP_PREFIX}}_{{@key}}"' +
                                 ' role="tab" data-toggle="tab">' +
                                 '{{get_string groupname ../component}}' +
                             '</a>' +
@@ -686,6 +687,7 @@ Y.namespace('M.atto_equation').Button = Y.Base.create('button', Y.M.editor_atto.
         });
         content = template({
             elementid: this.get('host').get('elementid'),
+            elementidescaped: this._escapeQuerySelector(this.get('host').get('elementid')),
             component: COMPONENTNAME,
             library: library,
             CSS: CSS,
@@ -710,7 +712,23 @@ Y.namespace('M.atto_equation').Button = Y.Base.create('button', Y.M.editor_atto.
             content = preview.responseText;
         }
         return content;
+    },
+
+    /**
+     * Escape special characters in string used as a JS query selector
+     *
+     * @method _excapeQuerySelector
+     * @param {string} selector
+     * @returns {string}
+     */
+    _escapeQuerySelector: function(selector) {
+
+        // Bootstrap requires that query selectors have special chars excaped.
+        // See: https://getbootstrap.com/docs/4.2/getting-started/javascript/#selectors
+
+        return selector.replace(/(:|\.|\[|\]|,|=|@)/g, '\\$1');
     }
+
 }, {
     ATTRS: {
         /**