diff options
10 files changed, 42 insertions, 4 deletions
diff --git a/mesonbuild/interpreterbase/interpreterbase.py b/mesonbuild/interpreterbase/interpreterbase.py index 365e2fd4b..47dd46f32 100644 --- a/mesonbuild/interpreterbase/interpreterbase.py +++ b/mesonbuild/interpreterbase/interpreterbase.py @@ -107,10 +107,11 @@ class InterpreterBase: self.handle_meson_version_from_ast() except mparser.ParseException as me: me.file = mesonfile - # try to detect parser errors from new syntax added by future - # meson versions, and just tell the user to update meson - self.ast = me.ast - self.handle_meson_version_from_ast() + if me.ast: + # try to detect parser errors from new syntax added by future + # meson versions, and just tell the user to update meson + self.ast = me.ast + self.handle_meson_version_from_ast() raise me def parse_project(self) -> None: diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py index 28235b613..baccd2753 100644 --- a/mesonbuild/mparser.py +++ b/mesonbuild/mparser.py @@ -96,6 +96,10 @@ class Token(T.Generic[TV_TokenTypes]): class Lexer: def __init__(self, code: str): + if code.startswith(codecs.BOM_UTF8.decode('utf-8')): + line, *_ = code.split('\n', maxsplit=1) + raise ParseException('Builder file must be encoded in UTF-8 (with no BOM)', line, lineno=0, colno=0) + self.code = code self.keywords = {'true', 'false', 'if', 'else', 'elif', 'endif', 'and', 'or', 'not', 'foreach', 'endforeach', diff --git a/test cases/failing/130 utf8 with bom/meson.build b/test cases/failing/130 utf8 with bom/meson.build new file mode 100644 index 000000000..492a0c691 --- /dev/null +++ b/test cases/failing/130 utf8 with bom/meson.build @@ -0,0 +1,3 @@ +project('utf8 with bom') + +subdir('subdir') diff --git a/test cases/failing/130 utf8 with bom/test.json b/test cases/failing/130 utf8 with bom/test.json new file mode 100644 index 000000000..2292bebe3 --- /dev/null +++ b/test cases/failing/130 utf8 with bom/test.json @@ -0,0 +1,8 @@ +{ + "stdout": [ + { + "line": "test cases/failing/130 utf8 with bom/meson.build:0:0: ERROR: Builder file must be encoded in UTF-8 (with no BOM)" + } + ] + } +
\ No newline at end of file diff --git a/test cases/failing/131 utf8 with bom subdir/meson.build b/test cases/failing/131 utf8 with bom subdir/meson.build new file mode 100644 index 000000000..8d3bbd7e8 --- /dev/null +++ b/test cases/failing/131 utf8 with bom subdir/meson.build @@ -0,0 +1,3 @@ +project('utf8 with bom subdir') + +subdir('subdir') diff --git a/test cases/failing/131 utf8 with bom subdir/subdir/meson.build b/test cases/failing/131 utf8 with bom subdir/subdir/meson.build new file mode 100644 index 000000000..dbf2b9cc7 --- /dev/null +++ b/test cases/failing/131 utf8 with bom subdir/subdir/meson.build @@ -0,0 +1 @@ +a = 'Hello, World!' diff --git a/test cases/failing/131 utf8 with bom subdir/test.json b/test cases/failing/131 utf8 with bom subdir/test.json new file mode 100644 index 000000000..72cc5152d --- /dev/null +++ b/test cases/failing/131 utf8 with bom subdir/test.json @@ -0,0 +1,8 @@ +{ + "stdout": [ + { + "line": "test cases/failing/131 utf8 with bom subdir/subdir/meson.build:0:0: ERROR: Builder file must be encoded in UTF-8 (with no BOM)" + } + ] + } +
\ No newline at end of file diff --git a/test cases/failing/132 utf8 with bom options/meson.build b/test cases/failing/132 utf8 with bom options/meson.build new file mode 100644 index 000000000..50413e031 --- /dev/null +++ b/test cases/failing/132 utf8 with bom options/meson.build @@ -0,0 +1 @@ +project('utf8 with bom options') diff --git a/test cases/failing/132 utf8 with bom options/meson.options b/test cases/failing/132 utf8 with bom options/meson.options new file mode 100644 index 000000000..250c03279 --- /dev/null +++ b/test cases/failing/132 utf8 with bom options/meson.options @@ -0,0 +1 @@ +option('someoption', type : 'string', value : 'optval', description : 'An option') diff --git a/test cases/failing/132 utf8 with bom options/test.json b/test cases/failing/132 utf8 with bom options/test.json new file mode 100644 index 000000000..c09f48e6a --- /dev/null +++ b/test cases/failing/132 utf8 with bom options/test.json @@ -0,0 +1,8 @@ +{ + "stdout": [ + { + "line": "test cases/failing/132 utf8 with bom options/meson.options:0:0: ERROR: Builder file must be encoded in UTF-8 (with no BOM)" + } + ] + } +
\ No newline at end of file |
