Page MenuHomePhabricator

Unescape sequences in .cow files which look like escaped sequences
ClosedPublic

Authored by cspeckmim on Sep 26 2015, 3:21 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Apr 22, 3:42 PM
Unknown Object (File)
Fri, Apr 19, 3:38 PM
Unknown Object (File)
Wed, Apr 17, 3:12 PM
Unknown Object (File)
Thu, Apr 11, 7:20 AM
Unknown Object (File)
Sun, Apr 7, 12:46 PM
Unknown Object (File)
Sat, Apr 6, 6:43 AM
Unknown Object (File)
Mon, Apr 1, 1:00 PM
Unknown Object (File)
Sat, Mar 30, 10:06 AM
Subscribers

Details

Summary

Cowsay's .cow files are perl scripts which contain escaped character sequences. This results in an excess of backslashes in the rendered cow. This change replaces occurrences of \x with just x.

This change also introduces conditional unescaping based on whether the cowfile is an original perl-script cowfile or a plain ascii-art file.

Refs T9471

Test Plan

Use cowsay in a comment and verify that the rendered cow displays appropriately.
Use cowsay with the "dragon" cow and verify that the rendered dragon displays appropriately (contains \@ sequence).

Diff Detail

Repository
rPHU libphutil
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

cspeckmim retitled this revision from to Unescape sequences in .cow files which look like escaped sequences.
cspeckmim updated this object.
cspeckmim edited the test plan for this revision. (Show Details)
cspeckmim added a reviewer: epriestley.

What do you think about only doing this if the .cow file is really a perl script (i.e., we removed a perl variable declaration near line 53)? Then we wouldn't need the cube.test changes, and defining new .cow artfiles would be easier.

On the one hand, this is a problem of my own making by parsing a flat .cow file format that I made up.

But having the .cow format be "a perl script that declares a variable named $the_cow" was almost certainly just the easiest thing to implement, not a carefully considered architectural decision, and letting users define .cow files as flat ASCII art without escaping seems nice?

src/utils/PhutilCowsay.php
88

I'd expect this to capture (.) instead of (\S), what's the reasoning for not escaping space characters?

Additionally, I forgot to create an actual branch in git prior to making this diff -- do you prefer that all work happens in a separate branch or is it not a large concern? I checked in the phabcontrib documentation and didn't see anything off-hand that mentioned branches. I'm not thoroughly experienced with git as I am with hg.

src/utils/PhutilCowsay.php
88

I was originally thinking this should capture ., but was thinking in the case of:

---\

That you wouldn't want to escape that backslash. After updating the test case I realize now that it would be required to be escaped, as it's not a valid .cowfile.

This should be changed. Also I think this should probably happen before replacing the template variables, so as not to mess up any eyes/tongue that the user wants to use.

do you prefer that all work happens in a separate branch or is it not a large concern

Doesn't matter from my perspective, whatever's easiest on your end is good. (In Git, I'm normally never affected by how your working copy is organized and all my workflows are the same whether you're on a local branch or not.)

What do you think about only doing this if the .cow file is really a perl script

So always do variable-replacement, and only do "unescaping" if $the_cow was found/removed? It sounds like a new day for .cow makers.

So always do variable-replacement, and only do "unescaping" if $the_cow was found/removed? It sounds like a new day for .cow makers.

Yeah, I think this gives us the best behavior. If you're writing a new .cow you just put the art in the file without worrying about anything. I'm sure a .cow renaissance is close at hand now that it will be slightly easier to create new .cow files.

cspeckmim edited edge metadata.

Updated escape-sequence matching behavior and only replace for perl-style cowfiles

  1. Now match on (.) instead of (\S) to correct any escaped characters instead of just non-space characters.
  2. Moved the un-escaping to occur before the variable-replacement as not to affect the user parameters for tongue, eyes, etc.
  3. Determine if the cowfile template was an original perl script based on finding $the_cow, and only do un-escaping if found.
cspeckmim updated this object.

I will introduce another test case that defines $the_cow.

  • Added test case for perl-script cowfile
epriestley edited edge metadata.

Thanks!

(Not sure what's up with that unit test, but definitely unrelated.)

This revision is now accepted and ready to land.Sep 26 2015, 4:10 AM
This revision was automatically updated to reflect the committed changes.