summaryrefslogtreecommitdiff
path: root/addons/website/static/src/js/content
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2019-01-30 17:18:07 +0000
committerqsm-odoo <qsm@odoo.com>2019-01-31 17:35:07 +0000
commit0abfaeda96c2eaa868cc7fc5fa1926dfa90fc420 (patch)
tree66ed9aa5125802218c19983ccef296ec209265cd /addons/website/static/src/js/content
parent43888662ffdd51298d4995c20699a31ef029c39c (diff)
[FIX] website: prevent animation of anchor links with invalid fragment
Also secure the anchor creation to only allow valid names, that is letters, digits, underscores and hyphens. task-1913458 closes odoo/odoo#30701
Diffstat (limited to 'addons/website/static/src/js/content')
-rw-r--r--addons/website/static/src/js/content/snippets.animation.js19
1 files changed, 13 insertions, 6 deletions
diff --git a/addons/website/static/src/js/content/snippets.animation.js b/addons/website/static/src/js/content/snippets.animation.js
index 587cbca61d4..d2a653b0837 100644
--- a/addons/website/static/src/js/content/snippets.animation.js
+++ b/addons/website/static/src/js/content/snippets.animation.js
@@ -1094,14 +1094,21 @@ registry.anchorSlide = Animation.extend({
* @private
*/
_onAnimateClick: function (ev) {
- var hash = ev.currentTarget.hash;
+ if (this.$target[0].pathname !== window.location.pathname) {
+ return;
+ }
+ var hash = this.$target[0].hash;
+ if (!/^#[\w-]+$/.test(hash)) {
+ return;
+ }
var $anchor = $(hash);
- if ($anchor.length && $anchor.attr('data-anchor') && this.$target[0].pathname === window.location.pathname) {
- ev.preventDefault();
- $('html, body').animate({
- scrollTop: $anchor.offset().top,
- }, 500);
+ if (!$anchor.length || !$anchor.attr('data-anchor')) {
+ return;
}
+ ev.preventDefault();
+ $('html, body').animate({
+ scrollTop: $anchor.offset().top,
+ }, 500);
},
});