HomePhabricator

Fix ArcanistFormattedStringXHPASTLinterRule for PHP 8

Description

Fix ArcanistFormattedStringXHPASTLinterRule for PHP 8

Summary:
PHP 8's sprintf raises a ValueError when encountering unknown format
specifiers (previously it would eat the argument and print nothing), so
linting format strings like %Ls dies with an uncaught ValueError.

Fix this by using a custom callback during linting to turn all format
specifiers into %s and replace the dummy null argument with the original
format specifier, ensuring we always end up providing valid input to the
sprintf at the end. This has the nice property that the output of the
call to xsprintf is the original format string, though any
transformation into valid input would do.

Test Plan: Ran arc lint

Reviewers: epriestley, Blessed Reviewers

Reviewed By: epriestley, Blessed Reviewers

Subscribers: Korvin

Maniphest Tasks: T13588

Differential Revision: https://secure.phabricator.com/D21500

Details

Auditors
epriestley
Provenance
jrtc27Authored on Mon, Jan 11, 4:04 AM
industryPushed on Mon, Jan 11, 4:05 AM
Reviewer
Blessed Reviewers
Differential Revision
D21500: Fix ArcanistFormattedStringXHPASTLinterRule for PHP 8
Parents
rARC0adef03fdfee: Fix PhutilTypeSpec's regex handling for PHP 8
Branches
Unknown
Tags
Unknown
Tasks
T13588: PHP 8 Compatibility
Build Status
Buildable 24990
Build 34480: Run Core Tests

Event Timeline

epriestley added a subscriber: epriestley.

See D21500 for discussion, the test failure was an interaction between callbacks specified in C::m form and $callback() inside xsprintf() under old versions of PHP. Resolved by D21505.

All concerns with this commit have now been addressed.Mon, Jan 11, 4:41 AM