-
Couldn't load subscription status.
- Fork 544
Report invalid printf placeholder #4478
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
Conversation
e13d386 to
5603955
Compare
This pull request has been marked as ready for review.
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.
Adding a second parameter does not solve the error since %%% was invalid placeholder.
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.
This was producing an error https://3v4l.org/2dPI6
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.
we had such test problems in the past. I wonder whether we can somehow detect such bogus tests
(in the general case, not just in (s)printf)
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.
Would be nice to know what the invalid placeholder is and its position. Otherwise it'd be hard to debug with long format strings as %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%.
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.
I thought about this and I was wondering if we should iterate and add more details with acceptsReasonsTip later because:
-
This would require some weird signature for getPrintfPlaceholdersCount (Returning the count + the invalid placeholders/positions)
-
This would require to handle error message for
- Union string
%c%|%c%c%=> What would be the message ? 3rd position ? 5th position ? - String with multiple wrong placeholder like
%%% %%%=> Should we report all the invalid ones ?
- Union string
=> maybe you already have an idea about the format of the message @ondrejmirtes ?
Also maybe this belongs to bleeding edge only?
Also maybe this belongs to bleeding edge only?
I would have consider this kinda as a "bugfix".
Technically the sprintf('%') call should have been reported since there is was missing parameter https://3v4l.org/lAIAAs
I can put this behind bleeding edge, but that would mean adding an extra parameters to getPrintfPlaceholdersCount methods with something like getPrintfPlaceholdersCount($format, $reportInvalidPlaceholder). It's your call !
Uh oh!
There was an error while loading. Please reload this page.
Closes phpstan/phpstan#1889
Closes phpstan/phpstan#8547 (cc @staabm)