Missing break statements inside the switch ... case block in WC_Subscription::validate_date_updates() are causing an unexpected behavior when validating dates while changing subscription status.
According to PHP documentation,
when a case statement is found whose expression (...) matches the value of the switch expression (...) PHP continues to execute the statements until the end of the switch block.
So for example, when the case matches 'end' then all the following lines inside the block will be executed as if the expression would match 'cancelled', 'next_payment' and 'trial_end'.
How can this code break?
This shouldn't break because it doesn't add any new code, it only enhances existing code, ensuring expected behavior.
In this screenshot we can see how the debugger stops in the wrong case.
How to test this PR
Generate a subscription.
After the subscription period, generate renewal.
Move the subscription status to "On hold".
Make a PUT request to /wc/v3/subscriptions/{ID} with {"status":"cancelled"}
Before the fix, the request will throw an error: The next_payment date must occur after the start date.
After the fix, the request should change the subscription status to cancelled without errors.
Fixes #533
Description
Missing
break
statements inside theswitch
...case
block inWC_Subscription::validate_date_updates()
are causing an unexpected behavior when validating dates while changing subscription status.According to PHP documentation,
So for example, when the case matches 'end' then all the following lines inside the block will be executed as if the expression would match 'cancelled', 'next_payment' and 'trial_end'.
In this screenshot we can see how the debugger stops in the wrong case.
How to test this PR
The next_payment date must occur after the start date.
After the fix, the request should change the subscription status tocancelled
without errors.Product impact