| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 303c48f commit 1461c35
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -550,9 +550,14 @@ def parse_value(value: str) -> str: | |||
| 550 | 550 | ||
| 551 | 551 | while True: | |
| 552 | 552 | # We assume to read binary! | |
| 553 | - line = fp.readline().decode(defenc) | ||
| 554 | - if not line: | ||
| 553 | + raw_line = fp.readline() | ||
| 554 | + if not raw_line: | ||
| 555 | 555 | break | |
| 556 | + if lineno == 0 and raw_line.startswith(b"\xef\xbb\xbf"): | ||
| 557 | + # A UTF-8 BOM is not part of the content. git skips it, so a | ||
| 558 | + # config file written by a Windows editor still parses. | ||
| 559 | + raw_line = raw_line[3:] | ||
| 560 | + line = raw_line.decode(defenc) | ||
| 556 | 561 | lineno = lineno + 1 | |
| 557 | 562 | # Comment or blank line? | |
| 558 | 563 | if line.strip() == "" or self.re_comment.match(line): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -354,6 +354,17 @@ def test_comment_backslash_does_not_continue_value(self, rw_dir): | |||
| 354 | 354 | with GitConfigParser(config_path) as config: | |
| 355 | 355 | self.assertEqual(config.get_value("a", "x"), "two") | |
| 356 | 356 | ||
| 357 | + def test_utf8_bom_is_skipped_like_git(self): | ||
| 358 | + """git skips a UTF-8 BOM at the start of a config file, so one written by | ||
| 359 | + a Windows editor still parses. Expectations are what | ||
| 360 | + `git config -f <file> --list` prints on git 2.47.3.""" | ||
| 361 | + content = b"\xef\xbb\xbf[core]\n\tbare = true\n" | ||
| 362 | + config_file = io.BytesIO(content) | ||
| 363 | + config_file.name = "bom.config" | ||
| 364 | + config = GitConfigParser(config_file) | ||
| 365 | + config.read() | ||
| 366 | + self.assertIs(config.get_value("core", "bare"), True) | ||
| 367 | + | ||
| 357 | 368 | def test_config_value_with_trailing_new_line(self): | |
| 358 | 369 | config_content = b'[section-header]\nkey:"value\n"' | |
| 359 | 370 | config_file = io.BytesIO(config_content) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments