1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 10:12:41 +01:00

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:

562d36ef5f

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
This commit is contained in:
Valerio Bozzolan 2023-05-19 22:05:26 +02:00
parent 678c7a78be
commit 976a21f658

View file

@ -56,11 +56,22 @@ abstract class AphrontFormControl extends AphrontView {
return $this->label; return $this->label;
} }
/**
* Set the Caption
* The Caption shows a tip usually nearby the related input field.
* @param string|PhutilSafeHTML|null
* @return self
*/
public function setCaption($caption) { public function setCaption($caption) {
$this->caption = $caption; $this->caption = $caption;
return $this; return $this;
} }
/**
* Get the Caption
* The Caption shows a tip usually nearby the related input field.
* @return string|PhutilSafeHTML|null
*/
public function getCaption() { public function getCaption() {
return $this->caption; return $this->caption;
} }
@ -203,7 +214,11 @@ abstract class AphrontFormControl extends AphrontView {
$custom_class .= ' aphront-form-control-nolabel'; $custom_class .= ' aphront-form-control-nolabel';
} }
if (phutil_nonempty_string($this->getCaption())) { // The Caption can be stuff like PhutilSafeHTML and other objects that
// can be casted to a string. After this cast we have never null.
$has_caption = phutil_string_cast($this->getCaption()) !== '';
if ($has_caption) {
$caption = phutil_tag( $caption = phutil_tag(
'div', 'div',
array('class' => 'aphront-form-caption'), array('class' => 'aphront-form-caption'),