wmllint: extend Elvish Hunter's Windows sys.argv fix to cover more cases
While testing my next commit, I discovered that EH's fix works when there is only one argument, or if the offender is the last argument, but doesn't work with multiple entries. His fix is meant to work on each argument, but the (unintentionally) escaped quote no longer serves to end the argument, causing following arguments to be considered part of the same argument. Using split() allows us to break apart these misconjoined arguments. With rstrip(), we prevent an empty string that Windows will also complain it cannot find. However, if there are three or more arguments, there will still be lumped-together arguments unless all arguments up to the second from last also end with a backslash and quote. It is impossible to cover every possible case. The re.sub handles the probably rare case where a backslash before a quote comes within the argument rather than at the end. However, it will only work if there is only one argument. All this is unnecessary if the OS is not Windows (also, I haven't had the opportunity to test this on a non-Windows system to see if it has any side-effects there). So I've put it under a sys.platform condition.
This commit is contained in:
parent
06b4ef06c9
commit
71caf69975
1 changed files with 14 additions and 6 deletions
|
@ -2401,15 +2401,23 @@ if __name__ == '__main__':
|
|||
return line
|
||||
|
||||
try:
|
||||
# If a backslash comes before a quote, it will be interpreted as an
|
||||
# escape to a literal quote rather than a Windows directory delimiter,
|
||||
# causing Windows to find "no such file or directory". This block deals
|
||||
# with this issue, but it is impossible to handle all cases if multiple
|
||||
# (intended) arguments are involved.
|
||||
if arguments and sys.platform == 'win32':
|
||||
for i,arg in enumerate(arguments):
|
||||
if '"' in arg:
|
||||
arguments.remove(arg)
|
||||
arg = re.sub(r'([^ ])"([^ ])', r'\1\\\2', arg)
|
||||
for new in arg.rstrip('"').split('"'):
|
||||
arguments.insert(i, new.strip())
|
||||
i += 1
|
||||
|
||||
if not arguments:
|
||||
arguments = ["."]
|
||||
|
||||
# in certain situations, Windows' command prompt appends a double quote
|
||||
# to the command line parameters. This block takes care of this issue.
|
||||
for i,arg in enumerate(arguments):
|
||||
if arg.endswith('"'):
|
||||
arguments[i] = arg[:-1]
|
||||
|
||||
for dir in arguments:
|
||||
ofp = None
|
||||
for fn in allcfgfiles(dir):
|
||||
|
|
Loading…
Add table
Reference in a new issue