[FIX] website: facebook page id regexp

Some valid facebook pages appear as broken by the preview although
they load perfectly fine afterward.

At facebook, an id is required to perform requests to their graphql
endpoints. The ID is part of the URL of the page, sometime (like Odoo)
the ID is the name of the page and sometime (like LACME France) it is
a generated 9-digits id shown in the URL after the name of the page.

Example of two valid page URL and their page ID:

    https://www.facebook.com/Odoo
                             ^^^^
                             ----

    https://www.facebook.com/LACME-France-910072559192969
                                          ^^^^^^^^^^^^^^^
                             ----------------------------

`^` denotes the page id and what odoo uses as page id after the commit
`-` denotes what odoo used as page id before the commit

opw-19494444

closes odoo/odoo#31922

Signed-off-by: Julien Castiaux <Julien00859@users.noreply.github.com>
This commit is contained in:
Julien (juc) Castiaux
2019-03-19 10:26:58 +00:00
parent 36435b4ad7
commit 82c4393fd0
@@ -642,11 +642,11 @@ var FacebookPageDialog = weWidgets.Dialog.extend({
*/
_renderPreview: function () {
var self = this;
var match = this.fbData.href.match(/^(?:https?:\/\/)?(?:www\.)?(?:fb|facebook)\.com\/(\w+)/);
var match = this.fbData.href.match(/^(?:https?:\/\/)?(?:www\.)?(?:fb|facebook)\.com\/(?:([\w.]+)|[^/?#]+-([0-9]{15,16}))(?:$|[\/?# ])/);
if (match) {
// Check if the page exists on Facebook or not
$.ajax({
url: 'https://graph.facebook.com/' + match[1] + '/picture',
url: 'https://graph.facebook.com/' + (match[2] || match[1]) + '/picture',
statusCode: {
200: function () {
self._toggleWarning(true);