diff options
| author | Charles Brunet <charles.brunet@optelgroup.com> | 2024-02-14 08:57:35 -0500 |
|---|---|---|
| committer | Eli Schwartz <eschwartz93@gmail.com> | 2024-02-23 15:00:39 -0500 |
| commit | 715dc27b2b8432d9749df985f262de8a8347c59b (patch) | |
| tree | 17acc9cf96161b31fd403d0062bedc72c80fc7b2 /mesonbuild/mparser.py | |
| parent | 138e0fe9841b44a6d0402b66bbd0c10966cfe87b (diff) | |
| download | meson-715dc27b2b8432d9749df985f262de8a8347c59b.tar.gz | |
Detect utf8 bom from meson build files
Some text editors on Windows may use utf8bom encoding by default.
Prevent crash and properly report misencoded files.
Fixes #12766.
Diffstat (limited to 'mesonbuild/mparser.py')
| -rw-r--r-- | mesonbuild/mparser.py | 4 |
1 files changed, 4 insertions, 0 deletions
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', |
