Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,9 @@ def replace_with_file_contents(fname):
:return: str - contents of file "fname"
"""
try:
with open(os.path.expanduser(fname[0])) as source_file:
# Any outer quotes are not part of the filename
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice little fix. It would be undesirable to create a file name with quotes in it.

The new behavior is much better.

unquoted_file = strip_quotes(fname[0])
with open(os.path.expanduser(unquoted_file)) as source_file:
result = source_file.read()
except IOError:
result = '< %s' % fname[0] # wasn't a file after all
Expand Down Expand Up @@ -2936,8 +2938,8 @@ def _build_main_parser(self, redirector, terminators, multilineCommands, legalCh
pyparsing.Optional(pipe + pyparsing.SkipTo(output_destination_parser ^ string_end,
ignore=do_not_parse)('pipeTo')) + \
pyparsing.Optional(output_destination_parser +
pyparsing.SkipTo(string_end,
ignore=do_not_parse).setParseAction(lambda x: x[0].strip())('outputTo'))
pyparsing.SkipTo(string_end, ignore=do_not_parse).
setParseAction(lambda x: strip_quotes(x[0].strip()))('outputTo'))

multilineCommand.setParseAction(lambda x: x[0])
oneline_command.setParseAction(lambda x: x[0])
Expand Down Expand Up @@ -2984,7 +2986,10 @@ def _build_input_source_parser(legalChars, commentInProgress):

input_mark = pyparsing.Literal('<')
input_mark.setParseAction(lambda x: '')
file_name = pyparsing.Word(legalChars + '/\\')

# Also allow spaces, slashes, and quotes
file_name = pyparsing.Word(legalChars + ' /\\"\'')

input_from = file_name('inputFrom')
input_from.setParseAction(replace_with_file_contents)
# a not-entirely-satisfactory way of distinguishing < as in "import from" from <
Expand Down