diff options
| author | Xavier Morel <xmo@openerp.com> | 2012-01-13 16:01:10 +0100 |
|---|---|---|
| committer | Xavier Morel <xmo@openerp.com> | 2012-01-13 16:01:10 +0100 |
| commit | a76f6d2a4efd17906c6ef1b80e5e5e9830c9307a (patch) | |
| tree | 532bcb269eef5f56808530db49a873e12533e249 /addons/web/controllers/main.py | |
| parent | db7470757392baf9da571fd86a0e17f354328fcd (diff) | |
[FIX] concatenated JS files blowing up when not terminated with a semicolon
If the final semicolon of an openerp module is forgotten and the next
file starts with an expression (such as a parens, because it's a
third-party module using the module pattern, see Backbone.js or jQuery
for examples), the JS parser will not perform semicolon insertion and
will instead try to execute the module's wrapper/initializer function
by passing it whatever follows it (generally an other function).
This usually results in an error and stuff blowing out everywhere for
no obvious reason.
Concatenation of JS files now adds an explicit semicolon between files
(ideally it should only add one if it's missing, but that would
require backtracking in the file while skipping comments &etc, can't
be arsed and double-semicolons don't hurt much) to avoid this issue.
bzr revid: xmo@openerp.com-20120113150110-47j90oishtjrib7s
Diffstat (limited to 'addons/web/controllers/main.py')
| -rw-r--r-- | addons/web/controllers/main.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 7081ce3ce32..ed515f5b4f1 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -56,12 +56,15 @@ def concat_xml(file_list): return ElementTree.tostring(root, 'utf-8'), files_timestamp -def concat_files(file_list, reader=None): +def concat_files(file_list, reader=None, intersperse=""): """ Concatenate file content return (concat,timestamp) concat: concatenation of file content, read by `reader` timestamp: max(os.path.getmtime of file_list) """ + if not file_list: + return '', None + if reader is None: def reader(f): with open(f) as fp: @@ -75,7 +78,7 @@ def concat_files(file_list, reader=None): files_timestamp = ftime files_content.append(reader(fname)) - files_concat = "".join(files_content) + files_concat = intersperse.join(files_content) return files_concat,files_timestamp html_template = """<!DOCTYPE html> @@ -180,7 +183,7 @@ class WebClient(openerpweb.Controller): @openerpweb.httprequest def js(self, req, mods=None): files = [f[0] for f in self.manifest_glob(req, mods, 'js')] - content,timestamp = concat_files(files) + content, timestamp = concat_files(files, intersperse=';') # TODO use timestamp to set Last mofified date and E-tag return req.make_response(content, [('Content-Type', 'application/javascript')]) @@ -431,7 +434,7 @@ class Session(openerpweb.Controller): @openerpweb.jsonrequest def modules(self, req): # Compute available candidates module - loadable = openerpweb.addons_manifest.iterkeys() + loadable = openerpweb.addons_manifest loaded = req.config.server_wide_modules candidates = [mod for mod in loadable if mod not in loaded] |
