[FIX] website: restore the seo_name field cleaning

Part of [1] was lost during the frontend>backend merge [2].
The SEO name field was not "slugified" anymore in JS, it led to 2
issues:
- Bad UX, one could type something and it would end up after save with
  something completely different
- 404/crash: as the generated URL in js (based on the seo name value)
  would not be slugified, it would redirect to that URL, which would not
  be found as the record URL in python would be slugified. There would
  be an URL mismatch between the python route and the JS redirect value.
  This could still somehow happen as the JS and PY slug are not doing
  the exact same things but at least this will restore what we had
  before and mitigate the issue.

Step to reproduce:
- Go to a blog post and open the SEO dialog
- In the custom URL input, type "créé"
- You will be redirected to `/@/blog/travel-1/créé-1`
This will be a 404 page, as the correct URL is now
`/@/blog/travel-1/cree-1`.

[1]: https://github.com/odoo/odoo/commit/c387ec19b4648ae52bf3210253febd7825745627
[2]: https://github.com/odoo/odoo/commit/31cc10b91dc7762e23b4bde9b945be0c4ce3fe3b

X-original-commit: 3c266751c41ab0a96494ccd6cd1a1fff3a6a7058
Part-of: odoo/odoo#105195
This commit is contained in:
Romain Derie
2022-11-07 17:59:52 +01:00
parent 6a10ad1c3c
commit 8c0db0a174
2 changed files with 24 additions and 1 deletions
@@ -280,6 +280,10 @@ class TitleDescription extends Component {
}, () => []);
}
//--------------------------------------------------------------------------
// Getters
//--------------------------------------------------------------------------
get seoNameUrl() {
return this.previousSeoName || this.props.seoNameDefault;
}
@@ -322,6 +326,24 @@ class TitleDescription extends Component {
}
return false;
}
//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------
/**
* @private
* @param {InputEvent} ev
*/
_updateInputValue(ev) {
// `NFKD` as in `http_routing` python `slugify()`
ev.target.value = ev.target.value.trim().normalize('NFKD').toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w-]+/g, '') // Remove all non-word chars
.replace(/-$/g, '') // Remove trailing -
.replace(/--+/g, '-'); // Replace multiple - with single -
this.seoContext.seoName = ev.target.value;
}
}
TitleDescription.template = 'website.TitleDescription';
TitleDescription.props = {
@@ -143,7 +143,8 @@
<div class="input-group-prepend">
<span class="input-group-text seo_name_pre" t-esc="seoNamePre"/>
</div>
<input type="text" t-model="seoContext.seoName" class="form-control" t-att-placeholder="props.seoNameDefault" />
<input type="text" class="form-control" t-att-placeholder="props.seoNameDefault"
t-on-input="_updateInputValue" t-att-value="seoContext.seoName"/>
<div class="input-group-append" title="Unalterable unique identifier">
<span class="input-group-text seo_name_post" t-esc="seoNamePost"/>
</div>