mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-21 14:22:40 +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:
parent
d343be5926
commit
35e127da57
3 changed files with 36 additions and 7 deletions
|
@ -71,14 +71,19 @@ final class PhutilCowsay extends Phobject {
|
|||
$template);
|
||||
}
|
||||
|
||||
$template = preg_replace_callback(
|
||||
$token_patterns = array(
|
||||
'/\\$([a-z]+)/',
|
||||
array($this, 'replaceTemplateVariable'),
|
||||
$template);
|
||||
if ($template === false) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Failed to replace template variables while rendering cow!'));
|
||||
'/\\${([a-z]+)}/',
|
||||
);
|
||||
foreach ($token_patterns as $token_pattern) {
|
||||
$template = preg_replace_callback(
|
||||
$token_pattern,
|
||||
array($this, 'replaceTemplateVariable'),
|
||||
$template);
|
||||
if ($template === false) {
|
||||
throw new Exception(
|
||||
pht('Failed to replace template variables while rendering cow!'));
|
||||
}
|
||||
}
|
||||
|
||||
$lines = $this->text;
|
||||
|
|
11
src/utils/__tests__/cowsay/sheep.expect
Normal file
11
src/utils/__tests__/cowsay/sheep.expect
Normal file
|
@ -0,0 +1,11 @@
|
|||
__________________
|
||||
< How are my eyes? >
|
||||
------------------
|
||||
\
|
||||
\
|
||||
__
|
||||
UooU\.'@@@@@@`.
|
||||
\__/(@@@@@@@@@@)
|
||||
(@@@@@@@@)
|
||||
`YY~~~~YY'
|
||||
|| ||
|
13
src/utils/__tests__/cowsay/sheep.test
Normal file
13
src/utils/__tests__/cowsay/sheep.test
Normal file
|
@ -0,0 +1,13 @@
|
|||
$thoughts
|
||||
$thoughts
|
||||
__
|
||||
U${eyes}U\.'@@@@@@`.
|
||||
\__/(@@@@@@@@@@)
|
||||
(@@@@@@@@)
|
||||
`YY~~~~YY'
|
||||
|| ||
|
||||
~~~~~~~~~~
|
||||
{
|
||||
"text": "How are my eyes?",
|
||||
"eyes": "oo"
|
||||
}
|
Loading…
Reference in a new issue