Page MenuHomePhorge

Fix exception handling a numeric git branch ("Call to phutil_nonempty_string() expected null or a string, got: int" in PhabricatorRepository)
ClosedPublic

Authored by aklapper on Apr 2 2025, 11:55.

Details

Summary

PHP casts an array key which is a string that contains a decimal integer automatically into int type.
Quoting https://www.php.net/manual/en/language.types.array.php#language.types.array.syntax: "Strings containing valid decimal ints, unless the number is preceded by a + sign, will be cast to the int type."

As we check git branch names via phutil_nonempty_string($key), this throws an exception.
Thus explicitly cast the int to string.

Closes T15640.

Test Plan

Diff Detail

Repository
rP Phorge
Branch
T15640 (branched from master)
Lint
Lint Warnings
SeverityLocationCodeMessage
Warningsrc/applications/diffusion/data/DiffusionGitBranch.php:109TXT3Line Too Long
Unit
Tests Passed
Build Status
Buildable 1839
Build 1839: arc lint + arc unit

Event Timeline

aklapper requested review of this revision.Apr 2 2025, 11:55

Check if the comments are interesting - thanks for this Phorgi patchi that seems lovely

src/applications/diffusion/data/DiffusionGitBranch.php
82–87

Maybe nice to add a minor PHPdoc here to say @return array and inform that the key is the branch name (and may be numeric) and the value is (?)

This revision is now accepted and ready to land.Apr 2 2025, 12:03