File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,15 +14,32 @@ def gatherheredocuments(tokenizer):
1414
1515
1616def string_quote_removal (word ):
17- """remove single quotes for heredoc
17+ """
18+ Remove surrounding quotes for heredoc token.
19+ This function should also remove escaped quotes (\\ ", \\ ')
20+ See definition in bash's source
21+ https://github.com/bminor/bash/blob/master/subst.c#L11892
22+
23+ >>> string_quote_removal("EOF")
24+ 'EOF'
1825 >>> string_quote_removal("'EOF'")
1926 'EOF'
20- >>> string_quote_removal("EOF")
27+ >>> string_quote_removal('"EOF"')
28+ 'EOF'
29+ >>> string_quote_removal('\\ "EOF\\ "')
2130 'EOF'
31+
32+ # TODO: confirm only first level of surrounding quotes should be removed
33+ >>> string_quote_removal('""EOF""')
34+ '"EOF"'
35+ >>> string_quote_removal('"\\ "EOF"\\ "')
36+ '\" EOF\" '
2237 """
23- quote_match = re .search ("^'(.*)'$" , word )
38+ # match input starting with a single, double, or escaped quote (' " \" \')
39+ # and ending with the same (optionally escaped) quote
40+ quote_match = re .search ("^(\\ \\ *[\" '])(.*)\\ 1$" , word )
2441 if quote_match :
25- word = quote_match .group (1 )
42+ word = quote_match .group (2 )
2643 return word
2744
2845
You can’t perform that action at this time.
0 commit comments