mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-05 17:00:58 +01:00
fix quote stripping
This commit is contained in:
parent
cc5d098b55
commit
9211f3a4da
2 changed files with 40 additions and 2 deletions
|
@ -23,7 +23,13 @@ from xonsh.platform import (
|
|||
from xonsh.tools import unthreadable, print_color
|
||||
from xonsh.replay import replay_main
|
||||
from xonsh.timings import timeit_alias
|
||||
from xonsh.tools import argvquote, escape_windows_cmd_string, to_bool, swap_values
|
||||
from xonsh.tools import (
|
||||
argvquote,
|
||||
escape_windows_cmd_string,
|
||||
to_bool,
|
||||
swap_values,
|
||||
strip_simple_quotes,
|
||||
)
|
||||
from xonsh.xontribs import xontribs_main
|
||||
from xonsh.ast import isexpression
|
||||
|
||||
|
@ -118,7 +124,7 @@ class Aliases(cabc.MutableMapping):
|
|||
if isexpression(val):
|
||||
# expansion substitution
|
||||
lexer = __xonsh__.execer.parser.lexer
|
||||
self._raw[key] = lexer.split(val)
|
||||
self._raw[key] = list(map(strip_simple_quotes, lexer.split(val)))
|
||||
else:
|
||||
# need to exec alias
|
||||
f = "<exec-alias:" + key + ">"
|
||||
|
|
|
@ -1979,6 +1979,38 @@ def RE_COMPLETE_STRING():
|
|||
return re.compile(ptrn, re.DOTALL)
|
||||
|
||||
|
||||
def strip_simple_quotes(s):
|
||||
"""Gets rid of single quotes, double quotes, single triple quotes, and
|
||||
single double quotes from a string, if present front and back of a string.
|
||||
Otherwiswe, does nothing.
|
||||
"""
|
||||
starts_single = s.startswith("'")
|
||||
starts_double = s.startswith('"')
|
||||
if not starts_single and not starts_double:
|
||||
return s
|
||||
elif starts_single:
|
||||
ends_single = s.endswith("'")
|
||||
if not ends_single:
|
||||
return s
|
||||
elif s.startswith("'''") and s.endswith("'''") and len(s) >= 6:
|
||||
return s[3:-3]
|
||||
elif len(s) >= 2:
|
||||
return s[1:-1]
|
||||
else:
|
||||
return s
|
||||
else:
|
||||
# starts double
|
||||
ends_double = s.endswith('"')
|
||||
if not ends_double:
|
||||
return s
|
||||
elif s.startswith('"""') and s.endswith('"""') and len(s) >= 6:
|
||||
return s[3:-3]
|
||||
elif len(s) >= 2:
|
||||
return s[1:-1]
|
||||
else:
|
||||
return s
|
||||
|
||||
|
||||
def check_for_partial_string(x):
|
||||
"""Returns the starting index (inclusive), ending index (exclusive), and
|
||||
starting quote string of the most recent Python string found in the input.
|
||||
|
|
Loading…
Add table
Reference in a new issue