@@ -1944,8 +1944,11 @@ def processcommand(cls, reader, command, replace=True):
1944
1944
continue
1945
1945
1946
1946
new_arg = ""
1947
+ has_dual_quote = "''" in word
1947
1948
new_word = reader ._replace (word , unquote_path = False )
1948
1949
new_word = reader ._replace (new_word , unquote_path = False )
1950
+ if not has_dual_quote :
1951
+ new_word = new_word .replace ("''" , "'" )
1949
1952
new_word = new_word .replace ("\\ {" , "{" ).replace ("\\ }" , "}" )
1950
1953
new_arg += new_word
1951
1954
newcommand += new_arg
@@ -1980,8 +1983,14 @@ def word_has_ended():
1980
1983
and ps .word
1981
1984
and ps .word [- 1 ] not in string .whitespace
1982
1985
)
1983
- or (cur_char == "{" and ps .depth == 0 and not ps .word .endswith ("\\ " ))
1984
- or (ps .depth == 0 and ps .word and ps .word [- 1 ] == "}" )
1986
+ or (
1987
+ cur_char == "{"
1988
+ and ps .depth == 0
1989
+ and not ps .word .endswith ("\\ " )
1990
+ and ps .word != "'"
1991
+ )
1992
+ or (ps .depth == 0 and ps .word and ps .word [- 1 ] == "}" and peek () != "'" )
1993
+ or (ps .depth == 0 and ps .word and ps .word [- 2 :] == "}'" )
1985
1994
or (cur_char not in string .whitespace and ps .word and ps .word .strip () == "" )
1986
1995
)
1987
1996
@@ -1995,6 +2004,12 @@ def yield_if_word_ended():
1995
2004
if word_has_ended ():
1996
2005
yield_this_word ()
1997
2006
2007
+ def peek ():
2008
+ try :
2009
+ return self .command [_i + 1 ]
2010
+ except IndexError :
2011
+ return ""
2012
+
1998
2013
def accumulate ():
1999
2014
ps .word += cur_char
2000
2015
@@ -2004,7 +2019,7 @@ def push_substitution():
2004
2019
def pop_substitution ():
2005
2020
ps .depth -= 1
2006
2021
2007
- for cur_char in self .command :
2022
+ for _i , cur_char in enumerate ( self .command ) :
2008
2023
if cur_char in string .whitespace :
2009
2024
if ps .depth == 0 :
2010
2025
yield_if_word_ended ()
@@ -2016,6 +2031,12 @@ def pop_substitution():
2016
2031
elif cur_char == "}" :
2017
2032
accumulate ()
2018
2033
pop_substitution ()
2034
+ elif cur_char == "'" :
2035
+ if ps .depth == 0 and ps .word [:2 ] == "'{" and ps .word [- 1 ] == "}" :
2036
+ accumulate ()
2037
+ else :
2038
+ yield_if_word_ended ()
2039
+ accumulate ()
2019
2040
else :
2020
2041
yield_if_word_ended ()
2021
2042
accumulate ()
0 commit comments