mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-39128: Fix email.utils.unquote() parameter parsing
This commit is contained in:
parent
630cd37bfa
commit
3fa13e8af5
3 changed files with 43 additions and 2 deletions
|
|
@ -357,8 +357,16 @@ def parseaddr(addr, *, strict=True):
|
|||
def unquote(str):
|
||||
"""Remove quotes from a string."""
|
||||
if len(str) > 1:
|
||||
if str.startswith('"') and str.endswith('"'):
|
||||
return str[1:-1].replace('\\\\', '\\').replace('\\"', '"')
|
||||
if str.startswith('"'):
|
||||
pos = 1
|
||||
while pos < len(str):
|
||||
if str[pos] == '\\' and pos + 1 < len(str):
|
||||
pos += 2
|
||||
elif str[pos] == '"':
|
||||
content = str[1:pos]
|
||||
return re.sub(r'\\(.)', r'\1', content)
|
||||
else:
|
||||
pos += 1
|
||||
if str.startswith('<') and str.endswith('>'):
|
||||
return str[1:-1]
|
||||
return str
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue