diff --git a/addons/web/static/src/views/fields/url/url_field.js b/addons/web/static/src/views/fields/url/url_field.js index a2408deff9d..78aadb9cbf9 100644 --- a/addons/web/static/src/views/fields/url/url_field.js +++ b/addons/web/static/src/views/fields/url/url_field.js @@ -21,16 +21,10 @@ export class UrlField extends Component { } get formattedHref() { - let value = ""; - if (typeof this.props.record.data[this.props.name] === "string") { - const shouldaddPrefix = !( - this.props.websitePath || - this.props.record.data[this.props.name].includes("://") || - /^\//.test(this.props.record.data[this.props.name]) - ); - value = shouldaddPrefix - ? `http://${this.props.record.data[this.props.name]}` - : this.props.record.data[this.props.name]; + let value = this.props.record.data[this.props.name]; + if (value && !this.props.websitePath) { + const regex = /^((ftp|http)s?:\/)?\//i; // http(s)://... ftp(s)://... /... + value = !regex.test(value) ? `http://${value}` : value; } return value; } diff --git a/addons/web/static/tests/views/fields/url_field_tests.js b/addons/web/static/tests/views/fields/url_field_tests.js index 162fa55a7dc..ab9b1892096 100644 --- a/addons/web/static/tests/views/fields/url_field_tests.js +++ b/addons/web/static/tests/views/fields/url_field_tests.js @@ -325,4 +325,20 @@ QUnit.module("Fields", (hooks) => { "Placeholder" ); }); + + QUnit.test("url field with non falsy, but non url value", async function (assert) { + serverData.models.partner.fields.foo.default = "odoo://hello"; + + await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: `
`, + }); + + assert.strictEqual( + target.querySelector(".o_field_widget[name='foo'] a").getAttribute("href"), + "http://odoo://hello" + ); + }); });