@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

AphrontFormControl: fix regression for some specific Captions

Summary:
Fix a specific problem when visiting some specific pages like this one:

/auth/config/edit/?provider=PhabricatorPhabricatorAuthProvider:

Regression introduced in:

562d36ef5f9e83dba5e3ca0244f9c4af9e1f7b2b

Stack trace:

[Fri May 19 14:23:35.506028 2023] [php7:notice] [pid 20439] [client 127.0.0.1:39692] [2023-05-19 14:23:35] EXCEPTION: (InvalidArgumentException) Call to phutil_nonempty_string() expected null or a string, got: PhutilSafeHTML. at [<arcanist>/src/utils/utils.php:2127]
[Fri May 19 14:23:35.506647 2023] [php7:notice] [pid 20439] [client 127.0.0.1:39692] arcanist(head=arcpatch-D25049, ref.master=c14785c3795c, ref.arcpatch-D25049=1b6412c24640), phorge(head=arcpatch-D25216_1, ref.master=2df7ea13a387, ref.arcpatch-D25216_1=02b40a9e25eb)
[Fri May 19 14:23:35.506661 2023] [php7:notice] [pid 20439] [client 127.0.0.1:39692] #0 <#2> phutil_nonempty_string(PhutilSafeHTML) called at [<phorge>/src/view/form/control/AphrontFormControl.php:206]
[Fri May 19 14:23:35.506665 2023] [php7:notice] [pid 20439] [client 127.0.0.1:39692] #1 <#2> phutil_tag(string, array, array) called at [<phorge>/src/view/form/PHUIFormLayoutView.php:54]
[Fri May 19 14:23:35.506667 2023] [php7:notice] [pid 20439] [client 127.0.0.1:39692] #2 <#2> PHUIFormLayoutView::render() called at [<phorge>/src/view/form/AphrontFormView.php:160]

We keep 100% backward compatibility, reproducing the implicit cast happening automatically before PHP 8.1

It has also been simplified the non-empty check since that is possible after casting to string.

Closes T15404

Test Plan:
- Visit the page mentioned in the commit summary
- no longer explodes
- you still don't see empty Captions
- you still see populated Captions
- you still see HTML rendered for populated Captions

Reviewers: O1 Blessed Committers, avivey

Reviewed By: O1 Blessed Committers, avivey

Subscribers: avivey, speck, tobiaswiese, Matthew, Cigaryno

Maniphest Tasks: T15404

Differential Revision: https://we.phorge.it/D25231

+16 -1
+16 -1
src/view/form/control/AphrontFormControl.php
··· 56 56 return $this->label; 57 57 } 58 58 59 + /** 60 + * Set the Caption 61 + * The Caption shows a tip usually nearby the related input field. 62 + * @param string|PhutilSafeHTML|null 63 + * @return self 64 + */ 59 65 public function setCaption($caption) { 60 66 $this->caption = $caption; 61 67 return $this; 62 68 } 63 69 70 + /** 71 + * Get the Caption 72 + * The Caption shows a tip usually nearby the related input field. 73 + * @return string|PhutilSafeHTML|null 74 + */ 64 75 public function getCaption() { 65 76 return $this->caption; 66 77 } ··· 203 214 $custom_class .= ' aphront-form-control-nolabel'; 204 215 } 205 216 206 - if (phutil_nonempty_string($this->getCaption())) { 217 + // The Caption can be stuff like PhutilSafeHTML and other objects that 218 + // can be casted to a string. After this cast we have never null. 219 + $has_caption = phutil_string_cast($this->getCaption()) !== ''; 220 + 221 + if ($has_caption) { 207 222 $caption = phutil_tag( 208 223 'div', 209 224 array('class' => 'aphront-form-caption'),