You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Variable file and listener arguments from command line cannot contain colons #1866
You are right that you cannot use Windows paths with drive letters as arguments to variables files from the command line. I guess that could be fixed by applying same logic to arguments that is currently applied to variable file name/path. I don't think that's a good solution, though, because the same problem occurs also if you would need to use colons in arguments otherwise.
One possible solution would be supporting also other argument separators. Basically we could specify few alternatives and use the one that is first. It would be even more flexible to just use the one that's next after the variable file name/path, but figuring out where the variable file ends is not trivial.
Suitable alternatives could be |;!#%&+. They ought to be fairly rare in paths and shouldn't thus accidentally appear in variable file paths. Many of them requires escaping on the command line, but that's something we cannot do much about.
How do you think about this @mwalle? Would being able to use alternative argument separators work for you? Would you have time and interest to look at implementing this and providing a pull request? We are targeting 2.8.7 release next week, so there's a change to get this into a release pretty soon.
I'll forward this to @dnoack who actually found this bug.
I don't think its a bad idea to support different seperators, but in the end you always have the same problem; that is you cannot use the seperator as a charater in your arguments.
Why don't we use an escape character like backslash to escape any 'real' colon? Eg. you could do sth like
I proposed being able to select the separator because that approach works so well with sed with substitution. Typically you use / to separate the pattern and the replacement, but you can also use other separators to avoid escaping /:
sed s/foo/bar/
sef s|a/c|d/c|
If we allow users to select which separator they want to use and support :;|#&+, I think it's fairly unlikely that there's a need to use all of them in arguments. This is the first reported problem about : used in arguments, so this isn't such a common problem in genera.
Using a backslash on the command line is problematic because it typically needs to be escaped itself.
I knew the comparison with sed will turn up ;) As I said i'm fine with it and already noticed the drawback of the backslash in windows environments. But i just want to mention that although sed supports any seperator, you can also escape it eg
sed s#my\#file#file#
ok but back on the topic. so we would split the string by all supported seperators to get the filename and then use the first character after the filename (if there is one) as the seperator to split the arguments.
As you already mentioned this will restrict the supported characters in the filename.
Yeah, I knew sed supports escaping. I typically don't use that approach, though, because avoiding the problem is easier. sed is also a unix tool and doesn't need to think about backslash being a path separator on Windows.
My plan was to use something like this:
index = re.search(re.escape(':;|#&+'), name).start()
separator = name[index]
I know this solution has limitations, but I don't expect to see problems in real life. I don't think we need a better solution and I definitely don't have interest to implement one myself for RF 2.8.7. If you want a better solution, I'm willing to accept pull requests.
changed the title [-]Arguments on variable file cannot contain absolute windows path names[/-][+]Variable file and listener arguments from command line cannot contain colons[/+]on Dec 9, 2014
As you already mentioned I fixed the problem with the absolute Windows path as arguments by applying the same logic as it is already used for the variable file name/path. Of course there is still the issue about using colons within the arguments or filename/path.
To ensure backwards compatibility, I would prefer a solution with an extra parameter for user defined seperators. If the user makes no statement for the separator it still will be ':'.
E.g. executing --variablefile '../folder/myscript.py&arg1:stillarg1&arg2' --Separator &
would result in
name = '..folder/myscript.py'
args = ['arg1:stillarg1', 'arg2']
and without --Seperator &, it would result in
name = '..folder/myscript.py&arg1'
args = ['stillarg1&arg2']
Because of the fact that one can use every character except '/' for a linux file name, I don't like the idea of selecting the separator by looking for the first character out of a set of chars, e.g. '|!#%&+#'. With an extra parameter for a user defined separator, you don't have to worry about the probabilities of an uncommon filename.
Although it is possible that file names can contain pretty much all characters, I don't consider that a serious problem. They are fairly rare in general, and especially in this usage you should be able to use a name that has no such characters.
I'm strongly against adding a new command line option to specify the separator.
I could consider setting the separator as part of the --variablefile/--listener argument like --variablefile sep=&varfile.py&arg:with:colons. I think that's a lot uglier and only very marginally safer than --variablefile varfile.py&arg:with:colons, though.
After thinking this a bit more, I realized that paths supporting pretty much all characters and us supporting a big list of possible separators can be a problem. The more separators we have, the more likely it is that there is an accidental match. This is especially true with characters like & and + that easily could be in a file or directory name.
Would it be enough if we'd just supported either : or ; as the separator? I don't think ; is too likely to appear in paths, so adding it as an alternative ought to be pretty safe. Just having these two separators would obviously mean that using both : and ; in arguments wouldn't work, but I don't think that is a too common scenario either. As I mentioned earlier, this was the first time that using colon in arguments was reported to be a problem, and colon is even used in Windows paths and thus likely more commonly needed than semicolon.
another 'solution' is to just fix windows pathnames. eg. at the moment the windows path guessing is just applied to the first two arguments. instead, we could look at all arguments and guess if it is a windows path and fix it. although i must admin this looks rather strange:
--variablefile C:\script.py:C:\data.txt
I guess this is the most common use case for a colon. Everything else could be workaround by the script because the programmer is responsible for the arguments passed to the script and can easily avoid using colons in the arguments.
semicolon seems problematic since shells will see that as the command terminator. I have similar objections with pipes and parenthesis and a few other special characters. While it can be worked around with quotes, I think it will add confusion for the less technically inclined.
$ pybot --variablefle foo;bar # gonna need quotes, or the shell will think that's two commands!
Just brainstorming a bit, maybe double-characters would work? eg:
$ pybot --variablefile C:\script.py::C:\data.txt
I imagine it's a pretty rare file that has double-colons in it.
I know semicolons, pipes, and many other characters are problematic on the command line. That's the reason most (all?) Robot options that need multiple parts use colon as the separator. Semicolon would be needed so rarely, and mainly on Windows where it is not a problem, that I don't see escaping it when needed would be too big a problem.
Is your idea that the separator can be one or two colons, whichever is used after the variable file or listener name? I guess that would work fairly well, but there's a small risk that someone is using something like --variablefile foo.py::xxx to give empty string as the first argument. Using a new character, especially one that's very unlikely to appear in paths, would be safer.
@jussimalinen had an idea that arguments could be quoted to allow using the colon inside them as a normal character. I tested this approach using Python's csv module to parse arguments, and everything worked nicely with foo:bar:"zap:pa". Unfortunately this causes a new problems if arguments themselves start or end with quote and they aren't quoted. I don't want to require users to follow csv quoting rules in general, and making such change now would be backwards incompatible.
After thinking about various possibilities, I think simply supporting ; as an alternative argument separator is the best solution. This solution has the following benefits:
Solves the problem of using absolute paths as arguments on Windows. This was the original reported problem.
Solution is simple to implement and explain (i.e. document).
Solution is nearly 100% backwards compatible. Problems arise only if variable file or listener path contains a colon.
No need for additional command line options or other configuration.
There are also problems:
Not possible to use both : and ; in arguments. I doubt there are real needs for this, though.
Outside Windows ; needs to be escaped on the shell. I don't think this is a big issue either because the enhancement is mainly for Windows and escaping isn't that complicated anyway.
If you have very strong reasons why using ; isn't a good idea please comment now. Let us also know if you would be interested provide a pull request implementing the above solution. If there are no comments, I'll implement this myself tomorrow in order to get this into RF 2.8.7.
I agree that simply supporting ; as alternative separator is, because of the simplicity and the mentioned points of backwards compatibility, a pretty good solution.
Currently I got other things to do, so I do not intend to make a pull request.
Activity
pekkaklarck commentedon Dec 8, 2014
You are right that you cannot use Windows paths with drive letters as arguments to variables files from the command line. I guess that could be fixed by applying same logic to arguments that is currently applied to variable file name/path. I don't think that's a good solution, though, because the same problem occurs also if you would need to use colons in arguments otherwise.
One possible solution would be supporting also other argument separators. Basically we could specify few alternatives and use the one that is first. It would be even more flexible to just use the one that's next after the variable file name/path, but figuring out where the variable file ends is not trivial.
Suitable alternatives could be
|;!#%&+. They ought to be fairly rare in paths and shouldn't thus accidentally appear in variable file paths. Many of them requires escaping on the command line, but that's something we cannot do much about.How do you think about this @mwalle? Would being able to use alternative argument separators work for you? Would you have time and interest to look at implementing this and providing a pull request? We are targeting 2.8.7 release next week, so there's a change to get this into a release pretty soon.
mwalle commentedon Dec 9, 2014
I'll forward this to @dnoack who actually found this bug.
I don't think its a bad idea to support different seperators, but in the end you always have the same problem; that is you cannot use the seperator as a charater in your arguments.
Why don't we use an escape character like backslash to escape any 'real' colon? Eg. you could do sth like
(ok at this time i see why this is cumbersome on windows ;) )
Mhh.. is it possible to use the forward slash on windows as a path seperator? So you could use
pekkaklarck commentedon Dec 9, 2014
I proposed being able to select the separator because that approach works so well with
sedwith substitution. Typically you use/to separate the pattern and the replacement, but you can also use other separators to avoid escaping/:If we allow users to select which separator they want to use and support
:;|#&+, I think it's fairly unlikely that there's a need to use all of them in arguments. This is the first reported problem about:used in arguments, so this isn't such a common problem in genera.Using a backslash on the command line is problematic because it typically needs to be escaped itself.
mwalle commentedon Dec 9, 2014
I knew the comparison with sed will turn up ;) As I said i'm fine with it and already noticed the drawback of the backslash in windows environments. But i just want to mention that although sed supports any seperator, you can also escape it eg
ok but back on the topic. so we would split the string by all supported seperators to get the filename and then use the first character after the filename (if there is one) as the seperator to split the arguments.
As you already mentioned this will restrict the supported characters in the filename.
pekkaklarck commentedon Dec 9, 2014
Yeah, I knew
sedsupports escaping. I typically don't use that approach, though, because avoiding the problem is easier.sedis also a unix tool and doesn't need to think about backslash being a path separator on Windows.My plan was to use something like this:
I know this solution has limitations, but I don't expect to see problems in real life. I don't think we need a better solution and I definitely don't have interest to implement one myself for RF 2.8.7. If you want a better solution, I'm willing to accept pull requests.
pekkaklarck commentedon Dec 9, 2014
The same problem occurs also with listeners. I'll update issue title accordingly.
[-]Arguments on variable file cannot contain absolute windows path names[/-][+]Variable file and listener arguments from command line cannot contain colons[/+]dnoack commentedon Dec 10, 2014
As you already mentioned I fixed the problem with the absolute Windows path as arguments by applying the same logic as it is already used for the variable file name/path. Of course there is still the issue about using colons within the arguments or filename/path.
To ensure backwards compatibility, I would prefer a solution with an extra parameter for user defined seperators. If the user makes no statement for the separator it still will be
':'.E.g. executing
--variablefile '../folder/myscript.py&arg1:stillarg1&arg2' --Separator &would result in
and without
--Seperator &, it would result inBecause of the fact that one can use every character except '/' for a linux file name, I don't like the idea of selecting the separator by looking for the first character out of a set of chars, e.g. '|!#%&+#'. With an extra parameter for a user defined separator, you don't have to worry about the probabilities of an uncommon filename.
pekkaklarck commentedon Dec 10, 2014
Although it is possible that file names can contain pretty much all characters, I don't consider that a serious problem. They are fairly rare in general, and especially in this usage you should be able to use a name that has no such characters.
I'm strongly against adding a new command line option to specify the separator.
I could consider setting the separator as part of the
--variablefile/--listenerargument like--variablefile sep=&varfile.py&arg:with:colons. I think that's a lot uglier and only very marginally safer than--variablefile varfile.py&arg:with:colons, though.pekkaklarck commentedon Dec 11, 2014
After thinking this a bit more, I realized that paths supporting pretty much all characters and us supporting a big list of possible separators can be a problem. The more separators we have, the more likely it is that there is an accidental match. This is especially true with characters like
&and+that easily could be in a file or directory name.Would it be enough if we'd just supported either
:or;as the separator? I don't think;is too likely to appear in paths, so adding it as an alternative ought to be pretty safe. Just having these two separators would obviously mean that using both:and;in arguments wouldn't work, but I don't think that is a too common scenario either. As I mentioned earlier, this was the first time that using colon in arguments was reported to be a problem, and colon is even used in Windows paths and thus likely more commonly needed than semicolon.mwalle commentedon Dec 11, 2014
another 'solution' is to just fix windows pathnames. eg. at the moment the windows path guessing is just applied to the first two arguments. instead, we could look at all arguments and guess if it is a windows path and fix it. although i must admin this looks rather strange:
I guess this is the most common use case for a colon. Everything else could be workaround by the script because the programmer is responsible for the arguments passed to the script and can easily avoid using colons in the arguments.
boakley commentedon Dec 12, 2014
semicolon seems problematic since shells will see that as the command terminator. I have similar objections with pipes and parenthesis and a few other special characters. While it can be worked around with quotes, I think it will add confusion for the less technically inclined.
Just brainstorming a bit, maybe double-characters would work? eg:
I imagine it's a pretty rare file that has double-colons in it.
pekkaklarck commentedon Dec 12, 2014
I know semicolons, pipes, and many other characters are problematic on the command line. That's the reason most (all?) Robot options that need multiple parts use colon as the separator. Semicolon would be needed so rarely, and mainly on Windows where it is not a problem, that I don't see escaping it when needed would be too big a problem.
Is your idea that the separator can be one or two colons, whichever is used after the variable file or listener name? I guess that would work fairly well, but there's a small risk that someone is using something like
--variablefile foo.py::xxxto give empty string as the first argument. Using a new character, especially one that's very unlikely to appear in paths, would be safer.pekkaklarck commentedon Dec 17, 2014
@jussimalinen had an idea that arguments could be quoted to allow using the colon inside them as a normal character. I tested this approach using Python's
csvmodule to parse arguments, and everything worked nicely withfoo:bar:"zap:pa". Unfortunately this causes a new problems if arguments themselves start or end with quote and they aren't quoted. I don't want to require users to follow csv quoting rules in general, and making such change now would be backwards incompatible.pekkaklarck commentedon Dec 17, 2014
After thinking about various possibilities, I think simply supporting
;as an alternative argument separator is the best solution. This solution has the following benefits:There are also problems:
:and;in arguments. I doubt there are real needs for this, though.;needs to be escaped on the shell. I don't think this is a big issue either because the enhancement is mainly for Windows and escaping isn't that complicated anyway.If you have very strong reasons why using
;isn't a good idea please comment now. Let us also know if you would be interested provide a pull request implementing the above solution. If there are no comments, I'll implement this myself tomorrow in order to get this into RF 2.8.7.dnoack commentedon Dec 17, 2014
I agree that simply supporting
;as alternative separator is, because of the simplicity and the mentioned points of backwards compatibility, a pretty good solution.Currently I got other things to do, so I do not intend to make a pull request.
Support ';' as alternative arg sep w/ listeners and variable files.
UG: Documented using ';' as argument separator with listeners and var…