-
Notifications
You must be signed in to change notification settings - Fork 351
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
Avoid invalid time-range #1275
Avoid invalid time-range #1275
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1275 +/- ##
=========================================
Coverage 97.12% 97.12%
- Complexity 2775 2778 +3
=========================================
Files 174 174
Lines 8025 8030 +5
=========================================
+ Hits 7794 7799 +5
Misses 231 231
Continue to review full report at Codecov.
|
Note: I can add some unit test cases tomorrow. |
Oh, "tomorrow" was 4 days ago! I will look at the weekend. |
42f707b
to
e8d52d3
Compare
e8d52d3
to
8aed988
Compare
Sorry about the cut-paste in the unit tests. But there were already a bunch of test cases like that. It could have some @ByteHamster @DeepDiver1975 @staabm or anyone, please review. |
Sorry for the late reply. The change looks a bit hacky, to be honest, but I do not know enough about sabre/dav to be able to properly review this PR. |
$timeRange = []; | ||
} | ||
|
||
foreach (['start', 'end'] as $value) { |
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.
random idea: What do you think about throwing exceptions on invalid input instead?
Related: I would love to get a more specific phpdoc for $filter, so phpstan/psalm could tell the caller about invalid parameters at analysis time
It was trying to do something "reasonable" if a caller passes Actually there are plenty of things that might or might not be passed in Of course it would also be good to find out what the caller has been sending in Actually there might be plenty more places like this. I will have another look tomorrow. |
8aed988
to
b736a73
Compare
b736a73
to
8eb1f08
Compare
See #1319 |
Issue: sabre-io/Baikal#929
It is possible to call
calendarQuery
with all sorts of not-so-valid/expected stuff in$filters
array.In particular, it seems that
time-range
gets a boolean value (probablyfalse
?) in some cases, rather than being an array with some ofstart
andend
keys. That causes PHP 7.4 to complain when we try to access things like$timeRange['start']
When this happens, set it to an array. If
start
orend
is missing, set tofalse
so that these keys exist for the later code to process.Note: there are plenty of other assumptions made about what exists
$filters
array passed tocalendarQuery
, but I am not attempting to fix the whole universe. For example:If you specify
comp-filters
but leave outprop-filters
completely, then a message will be emitted on PHP 7.4 complaining about the reference to non-existent array keyprop-filters
.There are lots of places that can have
array_key_exists
orisset
checks, and either fill in empty default values orthrow new \InvalidArgumentException