Page MenuHomePhabricator

D14170.id34238.diff
No OneTemporary

D14170.id34238.diff

diff --git a/src/utils/PhutilCowsay.php b/src/utils/PhutilCowsay.php
--- a/src/utils/PhutilCowsay.php
+++ b/src/utils/PhutilCowsay.php
@@ -45,11 +45,13 @@
// (and any comments in the file) away.
$template = phutil_split_lines($template, true);
$keep = array();
+ $is_perl_cowfile = false;
foreach ($template as $key => $line) {
if (preg_match('/^#/', $line)) {
continue;
}
if (preg_match('/^\s*\\$the_cow/', $line)) {
+ $is_perl_cowfile = true;
continue;
}
if (preg_match('/^\s*EOC\s*$/', $line)) {
@@ -59,6 +61,16 @@
}
$template = implode('', $keep);
+ // Original .cow files are perl scripts which contain escaped sequences.
+ // We attempt to unescape here by replacing any character preceded by a
+ // backslash/escape with just that character.
+ if ($is_perl_cowfile) {
+ $template = preg_replace(
+ '/\\\\(.)/',
+ '$1',
+ $template);
+ }
+
$template = preg_replace_callback(
'/\\$([a-z]+)/',
array($this, 'replaceTemplateVariable'),
diff --git a/src/utils/__tests__/cowsay/cube_perl.expect b/src/utils/__tests__/cowsay/cube_perl.expect
new file mode 100644
--- /dev/null
+++ b/src/utils/__tests__/cowsay/cube_perl.expect
@@ -0,0 +1,12 @@
+ __________________
+( I made a friend! )
+ ------------------
+ o
+ o
+ /---\__/---\\
+ | / .... \ ||
+ \ ..--.. //
+ |..(<3). ||
+ / ..--.. \\
+ | \ .... / ||
+ \---/--\---//
diff --git a/src/utils/__tests__/cowsay/cube_perl.test b/src/utils/__tests__/cowsay/cube_perl.test
new file mode 100644
--- /dev/null
+++ b/src/utils/__tests__/cowsay/cube_perl.test
@@ -0,0 +1,17 @@
+# test case for original perl-script cowfile
+$the_cow =
+ $thoughts
+ $thoughts
+ /---\\__/---\\\\
+ | / .... \\ ||
+ \\ ..--.. //
+ |..($eyes). ||
+ / ..--.. \\\\
+ | \\ .... / ||
+ \\---/--\\---//
+~~~~~~~~~~
+{
+ "text": "I made a friend!",
+ "action": "think",
+ "eyes": "<3"
+}

File Metadata

Mime Type
text/plain
Expires
Tue, Jan 14, 10:47 PM (8 h, 54 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6993183
Default Alt Text
D14170.id34238.diff (1 KB)

Event Timeline