[FIX] base: assets cannot load on Windows
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) <aab@odoo.com>
Co-authored-by: Lucas Perais <lpe@odoo.com>
Co-authored-by: François Georis <fge@odoo.com>
This commit is contained in:
co-authored by
Lucas Perais
François Georis
parent
27e72a9bbd
commit
d1b54c2edd
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user