Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c8e4aa0

Browse filesBrowse files
committed
Refactor quote parsing, to prepare for more checks
This refactors ConfigParser double-quote parsing near the single line double-quoted value parsing code, so that: - Code that parses the name is less intermixed with code that parses the value. - Conditional logic is less duplicated. - The `END` comment notation appears next to the code it describes. - The final `else` can be turned into one or more `elif` followed by `else` to cover different cases of `"..."` differently. (But those are not added here. This commit is purely a refactoring.) (The `pass` suite when `len(optval) < 2 or optval[0] != '"'` is awkward and not really justified right now, but it looks like it may be able to help with readabilty and help keep nesting down when new `elif` cases are added.)
1 parent 646dc16 commit c8e4aa0
Copy full SHA for c8e4aa0

1 file changed

+9-4Lines changed: 9 additions & 4 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎git/config.py‎

Copy file name to clipboardExpand all lines: git/config.py
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,18 +496,23 @@ def string_decode(v: str) -> str:
496496
if mo:
497497
# We might just have handled the last line, which could contain a quotation we want to remove.
498498
optname, vi, optval = mo.group("option", "vi", "value")
499+
optname = self.optionxform(optname.rstrip())
500+
499501
if vi in ("=", ":") and ";" in optval and not optval.strip().startswith('"'):
500502
pos = optval.find(";")
501503
if pos != -1 and optval[pos - 1].isspace():
502504
optval = optval[:pos]
503505
optval = optval.strip()
504-
optname = self.optionxform(optname.rstrip())
505-
if len(optval) > 1 and optval[0] == '"' and optval[-1] != '"':
506+
507+
if len(optval) < 2 or optval[0] != '"':
508+
pass # Nothing to treat as opening quotation.
509+
elif optval[-1] != '"':
506510
is_multi_line = True
507511
optval = string_decode(optval[1:])
508-
elif len(optval) > 1 and optval[0] == '"' and optval[-1] == '"':
509-
optval = optval[1:-1]
510512
# END handle multi-line
513+
else:
514+
optval = optval[1:-1]
515+
511516
# Preserves multiple values for duplicate optnames.
512517
cursect.add(optname, optval)
513518
else:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.