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
Variables acting as embedded arguments are not checked against regular expression #4069
Hi, I came across strange behaviour of RF regarding embedded arguments. I have keyword
Perform ${arg:[^ ]+}
Log To Console ${arg}
In other words, the argument cannot contain any space. Then, Perform abcd passes, as it contains no space. Perform ab cd fails with No keyword with name 'Perform ab cd' found, since it does contain a space. So far so good. But when I set the value with space to a variable and give it to the keyword: ${a} Set Variable ab cd and Perform ${a}, the keyword surprisingly passes (and logs ab cd). I expect it to fail as if in case when the non-matching value was given to the keyword directly.
When you use embedded arguments, Robot always allows using variables as arguments. That's by design and useful, but it could be more strict with actual variable values. Most importantly, if you specify a custom regexp, it could validate that the variable value matches that.
Need to then decide what to do if the variable value is not a string. Either we always accept such values or explicitly reject them. The latter sounds a bit better to me but would be backwards incompatible.
Hi, and what about converting value of the non-string variable to string and match it against the regexp? And then use its original value if it is accepted. Would it make sense?
Matching non-string values to regular expressions sounds a bit strange, but I guess it could make sense in this context. We'd only check the value if there's a custom regular expression anyway. I'm personally fine doing this either way.
This issue has a big risk of not making it to RF 5.0. It would be nice to have it, but we also want that release out as soon as possible. If you consider this issue important, comment here. If you really want to see it in RF 5.0, consider creating a pull request implementing it.
I had some time for coding on a train ride and decided to look at this myself. I noticed implementation isn't exactly trivial because we don't currently store custom patterns anywhere separately. I got a prototype working now but it needs a little cleanup as well as tests and a doc update.
I initially decided to make it so that if you specify a custom pattern, then the argument must be a string. That turned out to be a bad idea, because we even had acceptance tests with patterns like \d+ that were called with variables containing integers. That failing makes no sense. I thought about converting non-string values to strings before matching, but that's a bit risky with custom objects. My current thinking is that non-string values should just be always accepted.
This turned out to be quite a bit bigger task than I anticipated. Especially handling the \ escape character in patterns was pretty complicated. It didn't actually work correctly earlier.
The change is backwards incompatible in two ways:
Variable values must now match custom regular expressions. This is pretty obvious.
As mentioned above, handling escapes was buggy earlier. For example, if you wanted to match c:\\temp\\example (\\ needed because \ is an escape character), the pattern needed to be ${path:c:\\\\temp\\\\.*} i.e. the \ needed to be double escaped. The documentation didn't talk anything about double escaping so this was clearly a bug. Handling escapes was changed and now ${path:c:\\temp\\.*} works.
This functionality was disabled in 28a50a1. This issue was accidentally closed because GitHub interpreted the wording in the commit message so, but this is in fact still open and now targeted to RF 5.2. We may want to decide to postpone this further to RF 6.0, though, in which case the old behavior should be loudly deprecated in RF 5.2.
RF 6.0 (previously known as RF 5.1) enhanced conflict resolution significantly (#4454) and silently deprecated variables not matching custom embedded arguments patterns (#4462). We will make that deprecation more loud in RF 6.1 (#4524) and the behavior can then be finally changed in RF 7.0.
The planned loud deprecation of variables not matching patterns (#4524) wasn't done in RF 6.1 and there never was RF 6.2. In RF 7 we now need to decide should we do deprecation (#4524) or should we directly change the behavior (this issue). I'll now initially leave both of these to RF 7 scope, but if we do deprecation then we need to move this to RF 8 scope. If we decide to change the behavior right away, then the other issue can simply be closed.
Interestingly this behavior change affects also using custom patterns case-insensitively. Earlier if you had a keyword like Select ${animal:cat|dog}, you could use it as Select cat and Select Cat without problems. Making the pattern matching strict means that the match much be case-sensitive and as the result there's nowadays a deprecation warning from the latter. I believe matching being case-sensitive is a good thing, but there needs to be a way to make it case-insensitive. Issue #5242 handles that by allowing using inline flags like (?i).
Activity
pekkaklarck commentedon Aug 27, 2021
When you use embedded arguments, Robot always allows using variables as arguments. That's by design and useful, but it could be more strict with actual variable values. Most importantly, if you specify a custom regexp, it could validate that the variable value matches that.
Need to then decide what to do if the variable value is not a string. Either we always accept such values or explicitly reject them. The latter sounds a bit better to me but would be backwards incompatible.
MoreFamed commentedon Aug 29, 2021
Hi, and what about converting value of the non-string variable to string and match it against the regexp? And then use its original value if it is accepted. Would it make sense?
pekkaklarck commentedon Jan 19, 2022
Matching non-string values to regular expressions sounds a bit strange, but I guess it could make sense in this context. We'd only check the value if there's a custom regular expression anyway. I'm personally fine doing this either way.
pekkaklarck commentedon Jan 19, 2022
This issue has a big risk of not making it to RF 5.0. It would be nice to have it, but we also want that release out as soon as possible. If you consider this issue important, comment here. If you really want to see it in RF 5.0, consider creating a pull request implementing it.
pekkaklarck commentedon Aug 5, 2022
I had some time for coding on a train ride and decided to look at this myself. I noticed implementation isn't exactly trivial because we don't currently store custom patterns anywhere separately. I got a prototype working now but it needs a little cleanup as well as tests and a doc update.
pekkaklarck commentedon Aug 5, 2022
I initially decided to make it so that if you specify a custom pattern, then the argument must be a string. That turned out to be a bad idea, because we even had acceptance tests with patterns like
\d+that were called with variables containing integers. That failing makes no sense. I thought about converting non-string values to strings before matching, but that's a bit risky with custom objects. My current thinking is that non-string values should just be always accepted.pekkaklarck commentedon Aug 10, 2022
This turned out to be quite a bit bigger task than I anticipated. Especially handling the
\escape character in patterns was pretty complicated. It didn't actually work correctly earlier.The change is backwards incompatible in two ways:
c:\\temp\\example(\\needed because\is an escape character), the pattern needed to be${path:c:\\\\temp\\\\.*}i.e. the\needed to be double escaped. The documentation didn't talk anything about double escaping so this was clearly a bug. Handling escapes was changed and now${path:c:\\temp\\.*}works.10 remaining items
pekkaklarck commentedon Sep 13, 2022
This functionality was disabled in 28a50a1. This issue was accidentally closed because GitHub interpreted the wording in the commit message so, but this is in fact still open and now targeted to RF 5.2. We may want to decide to postpone this further to RF 6.0, though, in which case the old behavior should be loudly deprecated in RF 5.2.
pekkaklarck commentedon Oct 31, 2022
RF 6.0 (previously known as RF 5.1) enhanced conflict resolution significantly (#4454) and silently deprecated variables not matching custom embedded arguments patterns (#4462). We will make that deprecation more loud in RF 6.1 (#4524) and the behavior can then be finally changed in RF 7.0.
pekkaklarck commentedon Aug 25, 2023
The planned loud deprecation of variables not matching patterns (#4524) wasn't done in RF 6.1 and there never was RF 6.2. In RF 7 we now need to decide should we do deprecation (#4524) or should we directly change the behavior (this issue). I'll now initially leave both of these to RF 7 scope, but if we do deprecation then we need to move this to RF 8 scope. If we decide to change the behavior right away, then the other issue can simply be closed.
oboehmer commentedon Aug 27, 2023
Not a surprise, I guess, for me opting to deprecate first. It will allow folks to remove the pattern instead of keywords failing suddenly.
pekkaklarck commentedon Aug 28, 2023
Yeah, let's take the safe route and deprecate this behavior properly first. I'll move this issue in to RF 8 scope.
pekkaklarck commentedon Oct 18, 2024
Interestingly this behavior change affects also using custom patterns case-insensitively. Earlier if you had a keyword like
Select ${animal:cat|dog}, you could use it asSelect catandSelect Catwithout problems. Making the pattern matching strict means that the match much be case-sensitive and as the result there's nowadays a deprecation warning from the latter. I believe matching being case-sensitive is a good thing, but there needs to be a way to make it case-insensitive. Issue #5242 handles that by allowing using inline flags like(?i).