[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
This commit is contained in:
parent
db74707573
commit
a76f6d2a4e
|
@ -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]
|
||||
|
||||
|
|
Loading…
Reference in New Issue