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; - 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 (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')) { + return; + } + ev.preventDefault(); + $('html, body').animate({ + scrollTop: $anchor.offset().top, + }, 500); }, }); diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js index 9f25a4d15b9..f51dda964db 100644 --- a/addons/website/static/src/js/editor/snippets.options.js +++ b/addons/website/static/src/js/editor/snippets.options.js @@ -1502,9 +1502,13 @@ options.registry.anchorName = options.Class.extend({ click: function () { var $input = this.$('.o_input_anchor_name'); var anchorName = $input.val().trim().replace(/\s/g, '_'); - var alreadyExists = $('#' + anchorName).length > 0; - $input.toggleClass('is-invalid', alreadyExists); - if (!alreadyExists) { + var isValid = /^[\w-]+$/.test(anchorName); + var alreadyExists = isValid && $('#' + anchorName).length > 0; + var anchorOK = isValid && !alreadyExists; + this.$('.o_anchor_not_valid').toggleClass('d-none', isValid); + this.$('.o_anchor_already_exists').toggleClass('d-none', !alreadyExists); + $input.toggleClass('is-invalid', !anchorOK); + if (anchorOK) { self._setAnchorName(anchorName); this.close(); } diff --git a/addons/website/static/src/xml/website.editor.xml b/addons/website/static/src/xml/website.editor.xml index 5b060389618..46d5de05c12 100644 --- a/addons/website/static/src/xml/website.editor.xml +++ b/addons/website/static/src/xml/website.editor.xml @@ -107,7 +107,10 @@
-
The chosen name already exists
+
+

The chosen name is not valid (use only a-Z A-Z 0-9 - _)

+

The chosen name already exists

+