sql-workbench/workbench
12
33
Fork
You've already forked workbench
18

Don't quote input/output when invoking external formatters #99

Closed
xitep wants to merge 1 commit from (deleted):master into master
pull from: (deleted):master
merge into: sql-workbench:master
sql-workbench:master
First-time contributor
Copy link

On unix/linux, the hard coded quotes around the input/output file names get passed (as part of the filenames) to my external formatter, which then is unable to open the files (since the quotes are not part of their name.) Unfortunately, I don't have access to a windows machine, so I'm not able to see if it possibly breaks anything there. It shouldn't. ProcessBuilder gets the precise list of arguments and should not do any further tokenisation.

A shell script as simple as the following can be used to test it (ie. to simply echo back the arguments to wb again):

#!/bin/sh

for i in "$@" ; do
 echo ">$i<"
done

ps: this issue made me upgrade my quite outdated wb installation 😊 ... many thanks for keeping it up and maintained all those years! 🙇

On unix/linux, the hard coded quotes around the input/output file names get passed (as part of the filenames) to my external formatter, which then is unable to open the files (since the quotes are not part of their name.) Unfortunately, I don't have access to a windows machine, so I'm not able to see if it possibly breaks anything there. It shouldn't. `ProcessBuilder` gets the precise list of arguments and should not do any further tokenisation. A shell script as simple as the following can be used to test it (ie. to simply echo back the arguments to wb again): ```sh #!/bin/sh for i in "$@" ; do echo ">$i<" done ``` ps: this issue made me upgrade my quite outdated wb installation 😊 ... many thanks for keeping it up and maintained all those years! 🙇

Thanks for the feedback.

On Windows the quoting is most certainly necessary, I will check if there is a universal way of doing that. Maybe by calling ProcessBuilder in a different way.

I also wonder if quoting is necessary if the temp file written ends up in a directory containing spaces - which would require quoting on Linux as well I assume.

Thanks for the feedback. On Windows the quoting is most certainly necessary, I will check if there is a universal way of doing that. Maybe by calling ProcessBuilder in a different way. I also wonder if quoting is necessary if the temp file written ends up in a directory containing spaces - which would require quoting on Linux as well I assume.
Author
First-time contributor
Copy link

the "trick" i applied (and hope would work for windows) is explained here: https://stackoverflow.com/a/12124972

the "trick" i applied (and hope would work for windows) is explained here: https://stackoverflow.com/a/12124972
Author
First-time contributor
Copy link

I also wonder if quoting is necessary if the temp file written ends up in a directory containing spaces

no, it'll work. indeed, i tested with ${wbin} expanding into a string with a space (i just changed the file template directly in the code.) such a temp file gets then correctly passed to the executable as one argument. (of course, it's then up to the program to not break it up further by whitespace.)

> I also wonder if quoting is necessary if the temp file written ends up in a directory containing spaces no, it'll work. indeed, i tested with `${wbin}` expanding into a string with a space (i just changed the file template directly in the code.) such a temp file gets then correctly passed to the executable as one argument. (of course, it's then up to the program to not break it up further by whitespace.)

A command line like ${wbin} will indeed work. But for a program that requires something like inputFile=${wbin} the filename has to be quoted (especially if there is another parameter after the inputFile)

A command line like `${wbin}` will indeed work. But for a program that requires something like `inputFile=${wbin}` the filename has to be quoted (especially if there is _another_ parameter after the `inputFile`)
Author
First-time contributor
Copy link

and would "inputFile=${wbin}" anotherParameter work? this is, the user explicitly quoting what belongs together and what is seen as separate arguments.

and would `"inputFile=${wbin}" anotherParameter` work? this is, the user explicitly quoting what belongs together and what is seen as separate arguments.

I decided to solve this by parsing the command line in a way that preserves any double quotes provided by the user.

Therefor I will close this PR (which I have integrated partly into my solution)

I decided to solve this by parsing the command line in a way that preserves any double quotes provided by the user. Therefor I will close this PR (which I have integrated partly into my solution)
Author
First-time contributor
Copy link

wonderful, works like a charm on my system! you even managed to preserve user provided quotes 👍 many thanks for the solution! 🙇

wonderful, works like a charm on my system! you even managed to preserve user provided quotes 👍 many thanks for the solution! 🙇

Pull request closed

This pull request cannot be reopened because the branch was deleted.
Sign in to join this conversation.
No reviewers
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
sql-workbench/workbench!99
Reference in a new issue
sql-workbench/workbench
No description provided.
Delete branch "(deleted):master"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?