Page MenuHomePhabricator

Add a linter rule for invalid octals
ClosedPublic

Authored by joshuaspence on Nov 30 2015, 11:35 AM.
Tags
None
Referenced Files
F14918338: D14604.id35346.diff
Thu, Feb 13, 8:47 PM
Unknown Object (File)
Sun, Feb 9, 3:19 AM
Unknown Object (File)
Mon, Feb 3, 3:21 AM
Unknown Object (File)
Sun, Feb 2, 2:37 AM
Unknown Object (File)
Fri, Jan 31, 9:52 AM
Unknown Object (File)
Wed, Jan 29, 9:12 PM
Unknown Object (File)
Wed, Jan 29, 9:12 PM
Unknown Object (File)
Wed, Jan 29, 9:12 PM
Subscribers

Details

Summary

PHP doesn't handle octals very well. Basically, it seems that any numeric scalar matching /^0\d+$/ will be treated as an octal, whereas this should be /^0[0-7]+$/. As a result, 08 and 09 are both treated as 0 (because they are invalid octals. This diff adds a linter rule to detect this abnormality.

Test Plan

Added unit tests.

Diff Detail

Repository
rARC Arcanist
Branch
master
Lint
Lint Passed
SeverityLocationCodeMessage
Advicesrc/lint/linter/xhpast/rules/ArcanistInvalidOctalNumericScalarXHPASTLinterRule.php:23XHP105Function Call Should Be Type Cast
Unit
Test Failures
Build Status
Buildable 9156
Build 10811: Run Core Tests
Build 10810: arc lint + arc unit

Event Timeline

joshuaspence retitled this revision from to Add a linter rule for invalid numerals.
joshuaspence updated this object.
joshuaspence edited the test plan for this revision. (Show Details)
epriestley added a reviewer: epriestley.
epriestley added inline comments.
src/lint/linter/xhpast/rules/__tests__/invalid-octal-numeric-scalar/octal.lint-test
3–4

Maybe include these test cases?

0
0.9
0xFf
0XFf
0b01
-08
This revision is now accepted and ready to land.Nov 30 2015, 7:35 PM
joshuaspence retitled this revision from Add a linter rule for invalid numerals to Add a linter rule for invalid octals.Dec 2 2015, 9:25 PM
joshuaspence updated this object.
joshuaspence edited the test plan for this revision. (Show Details)
joshuaspence marked an inline comment as done.
joshuaspence removed a subscriber: Korvin.
This revision was automatically updated to reflect the committed changes.