1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-21 22:32:41 +01:00

Fix rendering of cowsay sheep.cow

Summary:
In the templates of the external cowsay library, most replaceable tokens are specified as $var_name.
However, the sheep.cow and flaming-sheep.cow use the ${eyes} syntax instead. This is not recognised by PhutilCowsay.php resulting in incorrect rendering of the template.

This change updates PhutilCowsay.php to handle ${var_name} tokens as well as $var_name

cowsay(cow='sheep'){{{My eyes, my eyes!}}}

Test Plan:
In a Remarkup comment or document, add
```
cowsay(cow='sheep'){{{How do my eyes look now?}}}
```

When testing in differential, you don't even need to submit the comment.

Reviewers: O1 Blessed Committers, avivey

Reviewed By: O1 Blessed Committers, avivey

Subscribers: avivey, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Differential Revision: https://we.phorge.it/D25435
This commit is contained in:
sten 2023-09-11 11:06:33 +01:00
parent d343be5926
commit 35e127da57
3 changed files with 36 additions and 7 deletions

View file

@ -71,14 +71,19 @@ final class PhutilCowsay extends Phobject {
$template); $template);
} }
$template = preg_replace_callback( $token_patterns = array(
'/\\$([a-z]+)/', '/\\$([a-z]+)/',
'/\\${([a-z]+)}/',
);
foreach ($token_patterns as $token_pattern) {
$template = preg_replace_callback(
$token_pattern,
array($this, 'replaceTemplateVariable'), array($this, 'replaceTemplateVariable'),
$template); $template);
if ($template === false) { if ($template === false) {
throw new Exception( throw new Exception(
pht( pht('Failed to replace template variables while rendering cow!'));
'Failed to replace template variables while rendering cow!')); }
} }
$lines = $this->text; $lines = $this->text;

View file

@ -0,0 +1,11 @@
__________________
< How are my eyes? >
------------------
\
\
__
UooU\.'@@@@@@`.
\__/(@@@@@@@@@@)
(@@@@@@@@)
`YY~~~~YY'
|| ||

View file

@ -0,0 +1,13 @@
$thoughts
$thoughts
__
U${eyes}U\.'@@@@@@`.
\__/(@@@@@@@@@@)
(@@@@@@@@)
`YY~~~~YY'
|| ||
~~~~~~~~~~
{
"text": "How are my eyes?",
"eyes": "oo"
}