-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Support named parameters in allowParams* config keys #141
Conversation
34725e2
to
bfa8809
Compare
great, thank you. |
It will take some time, sorry. I'd like to add a thing or two which would allow a param when used as a named param or as a positional param. Currently that's not possible and may require a different config format so I don't want to release this and then change the format. I'm thinking about allowParam:
4:
value: foo
name: flags Or something like that. In the future another key might be added, I'm thinking |
Sure, take your time. |
Let's take the example you've added, it's a perfect example :-) (and let's forget about the flags param type problem mentioned earlier): json_decode('foo', flags: JSON_THROW_ON_ERROR); so you'd configure something like this: allowParam:
flags: ::JSON_THROW_ON_ERROR but then you or someone else, would add a code like json_decode('foo', false, 123, JSON_THROW_ON_ERROR); note no named params. The constant usage wouldn't be detected and the call would be disallowed. So you'd need to write a code like json_decode('foo', false, 123, flags: JSON_THROW_ON_ERROR); (name the param) and I don't think that's nice. A configuration like allowParam:
4: ::JSON_THROW_ON_ERROR
flags: ::JSON_THROW_ON_ERROR doesn't work either because the list is not an OR list and for the call to be allowed, you'd need to specify both params which is sort of impossible. So my idea is to somehow turn the list into an OR list and because I'll be adding a "type" field anyway (for the flags problem above), I think it makes sense to also add a "named" field:
The code would look for param on position 4 if its value is json_decode('foo', flags: JSON_THROW_ON_ERROR);
json_decode('foo', false, 123, JSON_THROW_ON_ERROR); I realized this is probably what many people would expect when addind tests here. As params are alredy objects, adding this shouldn't be very difficult, just a little bit 😅 Hope that helps :-) (And just for the record, I don't expect you to add those features, I'll happily add those myself, building upon your contribution, thanks for that 🙏) |
bfa8809
to
663b006
Compare
…amed For example ```neon allowParamsAnywhere: - position: 2 name: 'alert' value: true ``` All keys are optional although I'd definitely recommend adding both `position` and `name`. The `value` key doesn't need to be specified with `allowParams*AnyValue`. The old-style shortcusts still work but they're not recommended: ```neon allowParamsInAllowed: 1: 'foo' 2: true ```
663b006
to
a546464
Compare
Thanks for the initial implementation! I've added what I've described above and merged this now. I'll probably release it when I have the flags support (#142) unless you're in a hurry :-) |
Just released in 2.11.0, let me know if it works for you. Thanks 👍 |
Close #140