From d1b54c2eddc2adb3b5b3bb6976996fe307db27bd Mon Sep 17 00:00:00 2001 From: Bruno Boi Date: Thu, 8 Apr 2021 14:44:12 +0000 Subject: [PATCH] [FIX] base: assets cannot load on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Assets can not be loaded on Windows due to the OS path separator character ´\´. This commit fixes it. Specifically: - `os.path.split` needed to get changed because it only serves to split the last part of the path (equivalent to `str.rsplit(os.path.sep, 1)`). What we want instead is to replace all `os.path.sep` by `"/"`. - for a template file, when verifying that the path is safe we were trying to determine if it was including the string `{addon}/static/`. It should have been converted to the correct OS representation of a path. Now it is. - `_get_paths` method should return the OS-style paths for the template files and the web-style path for others. closes odoo/odoo#69290 X-original-commit: e8e724ad6c754484bc5f03ce3262d2337e476d42 Signed-off-by: Aaron Bohy (aab) Co-authored-by: Lucas Perais Co-authored-by: François Georis --- odoo/addons/base/models/ir_asset.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/odoo/addons/base/models/ir_asset.py b/odoo/addons/base/models/ir_asset.py index d4eeed22437..b12ab990093 100644 --- a/odoo/addons/base/models/ir_asset.py +++ b/odoo/addons/base/models/ir_asset.py @@ -35,7 +35,9 @@ WILDCARD_CHARACTERS = {'*', "?", "[", "]"} def fs2web(path): """Converts a file system path to a web path""" - return '/'.join(os.path.split(path)) + if os.path.sep == '/': + return path + return '/'.join(path.split(os.path.sep)) def can_aggregate(url): parsed = urls.url_parse(url) @@ -347,8 +349,10 @@ class IrAsset(models.Model): except (ValueError, FileNotFoundError): return False if path.rpartition('.')[2] in TEMPLATE_EXTENSIONS: + # normpath will strip the trailing /, which is why it has to be added afterwards + static_path = os.path.normpath("%s/static" % addon) + os.path.sep # Forbid xml to leak - return ("%s/static/" % addon) in path + return static_path in path return True len_paths = len(paths) @@ -359,7 +363,7 @@ class IrAsset(models.Model): # files are read from the file system. But web assets (scripts and # stylesheets) must be loaded using relative paths, hence the trimming # for non-xml file paths. - paths = [path if path.split('.')[-1] in TEMPLATE_EXTENSIONS else path[len(addons_path):] for path in paths] + paths = [path if path.split('.')[-1] in TEMPLATE_EXTENSIONS else fs2web(path[len(addons_path):]) for path in paths] else: addon = None