-
-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing cronvalidator to use more robust regular expressions #129
Conversation
…r targeting regexes Original regexes from https://stackoverflow.com/a/57639657/10139735 Signed-off-by: Adam Mellen <[email protected]>
Signed-off-by: Adam Mellen <[email protected]>
Edited the original comment to reflect that it will close the related issue. |
Please target the 1.x-develop branch. You may need to rebase 😨 |
Thanks for contributing this! I'll take a more in depth look this weekend. |
https://docs.oracle.com/cd/E12058_01/doc/doc.1014/e12030/cron_expressions.htm
(just as an example here - code written hastily!) The cron parser (under Sorry for the issue with being on the wrong branch btw - in my defence, PHPStorm defaulted to |
Haha no worries regarding using 1.x-develop vs 1.x. I think an AJAX call is kind of overkill. IMO, since this validation already exists when the cron is registered in the DB, we only need to do very "light" validation on the client side. I think we just want to prevent people putting in "asdlfkjasdlfj" for example 😆 So, if a user were to put an incorrect cron expression, they'd get an error when it runs and they'd go back and figure it out from there. |
function (validator, $) { | ||
|
||
const CRON_REGEXES = [ | ||
/((((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|\*) ?){5,7})/i, //Regular regex terms |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could probably get away with just this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, maybe this:
((((\d+,)+\d+|(\*,)\d+|(\d+(\/|-)\d+)|\d+|\*\/?) ?){5,7})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added support for something like */3
and *,5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If unsure, we could go for (\W+ ){4,6}\W+
- 5 or seven blocks, separated by space. And let the server handle the details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to implement either solution tbh - I think there's generally no harm with trying to validate for more terms, one thing to note is that we should ensure there's adequate server sided validation. Maybe we validate for what @schmengler is suggesting in the frontend, and then do a more stringent process in the controller?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. See if you can add some validation inside this save function.
This way we can get the loose client side validation and a better server side validation. From a UX perspective, if something doesn't pass the server side validation. They should be redirected to the edit page and a message should appear saying it's an invalid cron.
What do you guys think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ethan3600 I'm happy with that, I'll work on implementing that some point this week if I get the time. Sorry for the delayed response, btw - I had to mute notifications from the magento org and this ended up being one of the casualties! 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to apologize!! That's the beauty of open source. No due dates or deadlines! We just get to build cool stuff and share it :).
Hi any news about this branch is it stable ? |
UP |
Hey all, @Ethan3600 it looks like the PR is currently failing due to the |
Hey @MellenIO no worries at all! I've also not been paying too much attention to Github 😞. Regarding the failures, I also think it's because it's an old PR. I bet if you rebased on top of the 1.x branch it'll go away. |
This resolves #122 - by using a few more robust regular expressions (from this SO answer) we can better test for a wider range of regular expressions - including non-standard macros where available.