| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9d3aff0 commit fd7027c
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -606,7 +606,6 @@ def parse_value(value: str) -> str: | |||
| 606 | 606 | # next line is appended before the complete value is | |
| 607 | 607 | # parsed. An even number means the last backslash is | |
| 608 | 608 | # escaped and the value ends there. | |
| 609 | - continued = False | ||
| 610 | 609 | while True: | |
| 611 | 610 | if not is_line_continuation(optval): | |
| 612 | 611 | break | |
@@ -620,9 +619,10 @@ def parse_value(value: str) -> str: | |||
| 620 | 619 | while joined.endswith("\n") or joined.endswith("\r"): | |
| 621 | 620 | joined = joined[:-1] | |
| 622 | 621 | optval = optval[:-1] + joined | |
| 623 | - continued = True | ||
| 624 | - if continued: | ||
| 625 | - optval = parse_value(optval) | ||
| 622 | + # Git decodes escape sequences in unquoted values exactly as | ||
| 623 | + # it does in quoted ones, so a value that needs no line | ||
| 624 | + # continuation is parsed the same way. | ||
| 625 | + optval = parse_value(optval) | ||
| 626 | 626 | elif quote_open: | |
| 627 | 627 | # Opens quoting and does not close: appears to start multi-line quoting. | |
| 628 | 628 | is_multi_line = True | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,10 @@ | |||
| 1 | + [custom] | ||
| 2 | + hasnewline = first\nsecond | ||
| 3 | + hastab = first\tsecond | ||
| 4 | + hasbackslash = foo\\bar | ||
| 5 | + hasquote = ab\"cd | ||
| 6 | + hastrailingbackslash = word\\ | ||
| 7 | + ordinary = hello world | ||
| 8 | + withcolon = host:port | ||
| 9 | + withequals = key=value | ||
| 10 | + withhash = value#notcomment | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -365,7 +365,7 @@ def test_backslash_line_continuation(self): | |||
| 365 | 365 | (b"[a]\n\tk = one\\\n two ; ignored\n", "one two"), | |
| 366 | 366 | (b'[a]\n\tk = one\\\n "two"\n', "one two"), | |
| 367 | 367 | (b"[a]\n\tk = one\\\n two\\tthree\n", "one two\tthree"), | |
| 368 | - (b"[a]\n\tk = val\\\\\n next\n", "val\\\\"), | ||
| 368 | + (b"[a]\n\tk = val\\\\\n next\n", "val\\"), | ||
| 369 | 369 | (b"[a]\n\tk = end\\\n", "end"), | |
| 370 | 370 | (b"[alias]\n\tco = checkout \\\n\t\t-v\n", "checkout \t\t-v"), | |
| 371 | 371 | ] | |
@@ -1209,6 +1209,23 @@ def test_config_with_quotes_containing_escapes(self): | |||
| 1209 | 1209 | # Cases without quotes should still parse correctly even after those, too. | |
| 1210 | 1210 | self.assertEqual(cr.get("custom", "unquoted"), "good evening") | |
| 1211 | 1211 | ||
| 1212 | + def test_config_with_unquoted_escapes(self): | ||
| 1213 | + """Interpret Git's escapes in unquoted values, which git decodes just as it | ||
| 1214 | + does for quoted ones.""" | ||
| 1215 | + cr = GitConfigParser(fixture_path("git_config_unquoted_escapes"), read_only=True) | ||
| 1216 | + | ||
| 1217 | + self.assertEqual(cr.get("custom", "hasnewline"), "first\nsecond") | ||
| 1218 | + self.assertEqual(cr.get("custom", "hastab"), "first\tsecond") | ||
| 1219 | + self.assertEqual(cr.get("custom", "hasbackslash"), R"foo\bar") | ||
| 1220 | + self.assertEqual(cr.get("custom", "hasquote"), 'ab"cd') | ||
| 1221 | + self.assertEqual(cr.get("custom", "hastrailingbackslash"), "word\\") | ||
| 1222 | + | ||
| 1223 | + # Values without escapes keep parsing as before. | ||
| 1224 | + self.assertEqual(cr.get("custom", "ordinary"), "hello world") | ||
| 1225 | + self.assertEqual(cr.get("custom", "withcolon"), "host:port") | ||
| 1226 | + self.assertEqual(cr.get("custom", "withequals"), "key=value") | ||
| 1227 | + self.assertEqual(cr.get("custom", "withhash"), "value") | ||
| 1228 | + | ||
| 1212 | 1229 | def test_get_values_works_without_requiring_any_other_calls_first(self): | |
| 1213 | 1230 | file_obj = self._to_memcache(fixture_path("git_config_multiple")) | |
| 1214 | 1231 | cr = GitConfigParser(file_obj, read_only=True) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments