| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 075a664 commit 60dd946
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -467,6 +467,19 @@ def string_decode(v: str) -> str: | |||
| 467 | 467 | ||
| 468 | 468 | # END string_decode | |
| 469 | 469 | ||
| 470 | + def is_line_continuation(value: str) -> bool: | ||
| 471 | + quoted = escaped = False | ||
| 472 | + for char in value: | ||
| 473 | + if escaped: | ||
| 474 | + escaped = False | ||
| 475 | + elif char == "\\": | ||
| 476 | + escaped = True | ||
| 477 | + elif char == '"': | ||
| 478 | + quoted = not quoted | ||
| 479 | + elif char in "#;" and not quoted: | ||
| 480 | + return False | ||
| 481 | + return escaped | ||
| 482 | + | ||
| 470 | 483 | while True: | |
| 471 | 484 | # We assume to read binary! | |
| 472 | 485 | line = fp.readline().decode(defenc) | |
@@ -520,8 +533,7 @@ def string_decode(v: str) -> str: | |||
| 520 | 533 | # included). An even number means the last backslash | |
| 521 | 534 | # is escaped and the value ends there. | |
| 522 | 535 | while True: | |
| 523 | - trailing = len(optval) - len(optval.rstrip("\\")) | ||
| 524 | - if trailing % 2 == 0: | ||
| 536 | + if not is_line_continuation(optval): | ||
| 525 | 537 | break | |
| 526 | 538 | continuation = fp.readline() | |
| 527 | 539 | if not continuation: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -163,6 +163,19 @@ def test_backslash_line_continuation(self): | |||
| 163 | 163 | key = "co" if section == "alias" else "k" | |
| 164 | 164 | self.assertEqual(config.get_value(section, key), expected) | |
| 165 | 165 | ||
| 166 | + @with_rw_directory | ||
| 167 | + def test_comment_backslash_does_not_continue_value(self, rw_dir): | ||
| 168 | + config_path = osp.join(rw_dir, "config") | ||
| 169 | + with open(config_path, "wb") as config_file: | ||
| 170 | + config_file.write(b"[a]\n\tk = one\\\n two ; ignored \\\n\tx = two\n") | ||
| 171 | + | ||
| 172 | + with GitConfigParser(config_path, read_only=False) as config: | ||
| 173 | + self.assertEqual(config.get_value("a", "x"), "two") | ||
| 174 | + config.set_value("a", "added", "three") | ||
| 175 | + | ||
| 176 | + with GitConfigParser(config_path) as config: | ||
| 177 | + self.assertEqual(config.get_value("a", "x"), "two") | ||
| 178 | + | ||
| 166 | 179 | def test_config_value_with_trailing_new_line(self): | |
| 167 | 180 | config_content = b'[section-header]\nkey:"value\n"' | |
| 168 | 181 | config_file = io.BytesIO(config_content) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments