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
Unknown Object (File)
Wed, Dec 11, 5:48 PM
Unknown Object (File)
Wed, Dec 11, 11:14 AM
Unknown Object (File)
Sun, Dec 8, 9:52 AM
Unknown Object (File)
Sat, Dec 7, 11:03 AM
Unknown Object (File)
Tue, Dec 3, 8:11 PM
Unknown Object (File)
Mon, Dec 2, 11:36 AM
Unknown Object (File)
Fri, Nov 29, 4:08 AM
Unknown Object (File)
Sun, Nov 24, 6:27 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 | || ||