@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.

Avoid exception rendering empty alt parameter of embedded image file

Summary:
When embedding an image file in Remarkup and setting an alt text without a value via `{F1234,alt}`, PhutilSimpleOptions returns a bool.
`phutil_nonempty_string()` does not appreciate this, so handle this cornercase which can happen while still slowly writing that markup.

See https://we.phorge.it/book/phorge/article/remarkup/#embedding-images for more context.

```
EXCEPTION: (InvalidArgumentException) Call to phutil_nonempty_string() expected null or a string, got: bool. at [<arcanist>/src/utils/utils.php:2147]
#0 <#2> phutil_nonempty_string(boolean) called at [<phorge>/src/applications/files/markup/PhabricatorEmbedFileRemarkupRule.php:201]
```

Followup to rP3999a286741dc5d8b92f5c4735033c4cbbf0dbea

Closes T16455

Test Plan: Embed an uploaded image file in a comment via `{F1234,alt}` remarkup.

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T16455

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

+6 -1
+6 -1
src/applications/files/markup/PhabricatorEmbedFileRemarkupRule.php
··· 104 104 } 105 105 } 106 106 107 + /** 108 + * @param string $option_string File display options. See "Embedding Images" 109 + * in @{article:Remarkup Reference} 110 + */ 107 111 private function getFileOptions($option_string) { 108 112 $options = array( 109 113 'size' => null, ··· 198 202 $alt = $options['alt']; 199 203 } 200 204 201 - if (!phutil_nonempty_string($alt)) { 205 + // PhutilSimpleOptions returns a bool if the option is set without a value 206 + if (is_bool($alt) || !phutil_nonempty_string($alt)) { 202 207 $alt = $file->getAltText(); 203 208 } 204 209