Skip to content

Commit

Permalink
MDL-68722 atto_equation: fix for form elements with special characters
Browse files Browse the repository at this point in the history
Element id's containing characters such as ':' would break the tab
selector in bootstrap.

This specifically affects the essay question type.
  • Loading branch information
matt-catalyst committed Oct 27, 2020
1 parent 3ba1073 commit 541e90c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,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>' +
Expand Down Expand Up @@ -688,6 +689,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,
Expand All @@ -712,7 +714,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: {
/**
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,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>' +
Expand Down Expand Up @@ -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,
Expand All @@ -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: {
/**
Expand Down
Loading

0 comments on commit 541e90c

Please sign in to comment.