Skip to content

Variables acting as embedded arguments are not checked against regular expression #4069

Description

@MoreFamed

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.

Activity

  1. pekkaklarck commented on Aug 27, 2021

    @pekkaklarck
    Member

    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.

  2. added this to the v5.0 milestone on Aug 27, 2021
  3. MoreFamed commented on Aug 29, 2021

    @MoreFamed
    Author

    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?

  4. pekkaklarck commented on Jan 19, 2022

    @pekkaklarck
    Member

    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.

  5. pekkaklarck commented on Jan 19, 2022

    @pekkaklarck
    Member

    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.

  6. modified the milestones: v5.0, v5.1 on Feb 15, 2022
  7. pekkaklarck commented on Aug 5, 2022

    @pekkaklarck
    Member

    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.

  8. pekkaklarck commented on Aug 5, 2022

    @pekkaklarck
    Member

    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.

  9. pekkaklarck commented on Aug 10, 2022

    @pekkaklarck
    Member

    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.
  10. 10 remaining items

  11. pekkaklarck commented on Sep 13, 2022

    @pekkaklarck
    Member

    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.

  12. pekkaklarck commented on Oct 31, 2022

    @pekkaklarck
    Member

    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.

  13. modified the milestones: v6.1, v7.0 on Oct 31, 2022
  14. pekkaklarck commented on Aug 25, 2023

    @pekkaklarck
    Member

    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.

  15. oboehmer commented on Aug 27, 2023

    @oboehmer
    Contributor

    Not a surprise, I guess, for me opting to deprecate first. It will allow folks to remove the pattern instead of keywords failing suddenly.

  16. pekkaklarck commented on Aug 28, 2023

    @pekkaklarck
    Member

    Yeah, let's take the safe route and deprecate this behavior properly first. I'll move this issue in to RF 8 scope.

  17. modified the milestones: v7.0, v8.0 on Aug 28, 2023
  18. pekkaklarck commented on Oct 18, 2024

    @pekkaklarck
    Member

    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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions