Page MenuHomePhabricator

Prevent exponential explosion of text-mode rendering of deeply nested blockquotes
ClosedPublic

Authored by epriestley on Oct 8 2015, 8:59 PM.
Tags
None
Referenced Files
F13059133: D14247.diff
Fri, Apr 19, 3:43 PM
Unknown Object (File)
Thu, Apr 11, 10:25 AM
Unknown Object (File)
Wed, Apr 10, 10:18 PM
Unknown Object (File)
Fri, Apr 5, 8:12 AM
Unknown Object (File)
Mon, Apr 1, 2:58 PM
Unknown Object (File)
Mon, Apr 1, 11:58 AM
Unknown Object (File)
Fri, Mar 29, 10:01 AM
Unknown Object (File)
Thu, Mar 28, 5:11 PM
Tokens
"Yellow Medal" token, awarded by cburroughs.

Details

Summary

Currently, the text-mode rendering of blockquotes doubles the number of lines in the input text. For example, a deeply nested input text like this:

>>>> a
>>>> b

...gets expanded to:

> a

> b

...then to:

> > a

> 

> > b

>

...and so on. If you nest something 28 levels deep, we generate 60 million lines from it.

So:

  • Stop doing that.
  • Make it look nicer.
  • Also make it put ">>>" at the beginning instead of "> > >".

Special thanks to @csilvers for hunting this down.

Test Plan

Added a unit test.

Generated mail for >>>>>>>>>>>>>>>>>>>>>>>>>>> REQUESTING CHANGES BECAUSE I'M ANGRY!.

Diff Detail

Repository
rPHU libphutil
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

epriestley retitled this revision from to Prevent exponential explosion of text-mode rendering of deeply nested blockquotes.
epriestley updated this object.
epriestley edited the test plan for this revision. (Show Details)
epriestley added a reviewer: chad.
epriestley added a subscriber: csilvers.

I'm not really understanding what's going on here -- I guess this function must be being called once per level of > seen?, though I don't see where any doubling happens -- but thanks for fixing it up!

The doubling is because $lines retains newlines (phutil_split_lines() is newline-preserving by default), and then we add extra newlines by imploding with "\n".

Every level basically applies the rule \n -> \n\n>

So we get:

\n
\n\n>
\n\n>\n\n>>
\n\n>\n\n>>\n\n>\n\n>>>
\n\n>\n\n>\n\n>\n\n>>>\n\n>\n\n>>\n\n>\n\n>>>>
chad edited edge metadata.
This revision is now accepted and ready to land.Oct 8 2015, 9:17 PM
This revision was automatically updated to reflect the committed changes.

TESTING DEEPLY NESTED BLOCKQUOTES FOR COMPLETENESS!!!

TESTING DEEPLY NESTED BLOCKQUOTES FOR COMPLETENESS!!!

This might be my new favorite visual effect!

Yeah, it's super cool! I was very impressed when we tracked it down.

____________ < such wow > ------------ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||