Page MenuHomePhabricator

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

Authored by epriestley on Oct 8 2015, 8:59 PM.

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
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

epriestley updated this revision to Diff 34397.Oct 8 2015, 8:59 PM
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 accepted this revision.Oct 8 2015, 9:17 PM
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!!!

avivey added a subscriber: avivey.Oct 8 2015, 9:22 PM

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.

chad added a comment.Oct 8 2015, 9:23 PM
____________ < such wow > ------------ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||