-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Custom Fields Validation regex field is too small #5719
Comments
This is pretty clearly excessive use of regular expressions. You're trying to leverage a regex to enforce the validity of several data types here, which is just generally a bad idea. You might consider splitting the relevant data into multiple fields or, better yet, writing a plugin to model it independently. |
I think this sentence sums this up pretty well. You could validate this using a much shorter regex (repeating patterns and recursion) to accomplish the same validation and I don't see any normal circumstance where you need to exceed 500 characters for validation. |
I'm not sure how you'd split this into multiple fields and still make it usable. I grant writing a plugin may work but that's a much bigger step from writing a regex.
I've got the regex down to 482 chars:
It sacrifices a bit of readability, not that the original was terribly readable in the first place. Given that regex processing of things like IP addresses are very complicated, and the relatively simple example above still occupies 482 chars, I thought this was a no-brainer, but I guess I'm wrong. In the meantime I've managed to squeeze the regex down below the limit, and I'll wait for #5451 as the much better solution |
Environment
Proposed Functionality
Increase the length of the Validation regex field in Custom Fields beyond the current 500 character limit (perhaps to something like 4096)
Use Case
In attempting to apply a validator to a custom field that defines static routes assigned to an IP on an interface, I use the following format:
<prefix>/<prefixlen> via gateway[,<prefix>/<prefixlen> via gateway]
Example:
192.0.2.0/24 via 203.0.113.1,198.51.100.0/24 via 203.0.113.1
To validate this accurately, use the following regular expression:
^\b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b\/\b([0-9]|[1-2][0-9]|3[1-2])\b via \b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b(,\b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b\/\b([0-9]|[1-2][0-9]|3[1-2])\b via \b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b)*$
Which is 838 characters long.
While the above expression could perhaps be shortened without sacrificing accuracy or increasing complexity, it serves to demonstrate how a regular expression to validate something even relatively simple can grow very long, and the current field length is inadequate
Database Changes
I expect minor changes to column sizes would be require
External Dependencies
None
The text was updated successfully, but these errors were encountered: