Skip to content

Improved check on property name#726

Merged
phil-davis merged 2 commits intosabre-io:masterfrom
KristofferFM:kristoffer-moellerhoej-improved-check-on-property-name
Dec 2, 2025
Merged

Improved check on property name#726
phil-davis merged 2 commits intosabre-io:masterfrom
KristofferFM:kristoffer-moellerhoej-improved-check-on-property-name

Conversation

@KristofferFM
Copy link
Copy Markdown
Contributor

Fixes that property name "0" crashes parser with 'LogicException: This code should not be reachable'

Specfically avoid the property name "0" crashes the parser with a 'LogicException: This code should not be reachable'
@codecov
Copy link
Copy Markdown

codecov bot commented Sep 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.76%. Comparing base (778bb46) to head (6eee31d).
⚠️ Report is 14 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #726   +/-   ##
=========================================
  Coverage     98.76%   98.76%           
- Complexity     1875     1876    +1     
=========================================
  Files            71       71           
  Lines          5345     5345           
=========================================
  Hits           5279     5279           
  Misses           66       66           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

continue;
}
if (isset($match['name']) && $match['name']) {
if (isset($match['name']) && 0 < strlen($match['name'])) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strlen() cannot be smaller then 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @staabm that part of the code is meant to check that the length of the property name is actually greater than zero. I think it is correct as is, please let me know if you still disagree.

(the codestyle requirements from php-cs-fixer requires the constant to be written first, that might look a bit confusing at first glance)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is checking that whatever is in 'name' is not (equivalent to) the empty string.
That is better than the previous test that checked if the value was "true" (the boolean true, or some non-zero number, or some string that does not "look like" zero.

Note: if somehow the 'name' is set to boolean false then its strlen(FALSE) will be the integer 0. That will throw the LogicException below, which is "a good thing".

So IMO this change is "a good thing".

@phil-davis phil-davis merged commit 192d94d into sabre-io:master Dec 2, 2025
8 checks passed
@phil-davis phil-davis mentioned this pull request Dec 2, 2025
@phil-davis
Copy link
Copy Markdown
Contributor

Backported to the 4.5 branch in PR #738

The code format changes were not valid for ancient PHP 7.1 and 7.2, so I didn't end up backporting those. (the 2nd commit in this PR)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants