Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page crashes when using a long series of space characters #473

Open
lautmaus opened this issue Feb 2, 2023 · 4 comments
Open

Page crashes when using a long series of space characters #473

lautmaus opened this issue Feb 2, 2023 · 4 comments

Comments

@lautmaus
Copy link

lautmaus commented Feb 2, 2023

Some combinations of plain string and long series of space characters causes too much recursion and crashes the page:

a
                                                                                                                                                      
a

Tested here: https://probablyup.com/markdown-to-jsx/

@lautmaus lautmaus changed the title Leading spaces cause recursion error Page crashes when using a long series of space characters Feb 2, 2023
@hectim
Copy link

hectim commented Mar 31, 2023

Happening to us too. Initially thought it was because of image rendering, but firefox throws an exception about recursion depth so I believe its the same issue

@itsamejoshab
Copy link

itsamejoshab commented Nov 9, 2023

Confirmed, ran into this with a block of SQL today that came from an IDE where whitespace was set to 4 spaces. The offending block of text:

WITH SalesByPrice AS
  (SELECT product_subcategory,
          ROUND(sale_price,2) AS sale_price,
          Avg(unit_qty_sold) unit_qty_sold,
          lag(sale_price, 1) OVER (PARTITION BY product_subcategory
                                   ORDER BY sale_price) Prevsale_price,
                                  lag(Avg(unit_qty_sold), 1) OVER (PARTITION BY product_subcategory
                                                                   ORDER BY sale_price) Prevunit_qty_sold

It took ~9 seconds to render

Tested here: https://probablyup.com/markdown-to-jsx/

@nx-victordiaz
Copy link

also on 7.4.0

@florianliebig
Copy link

I tracked this issue (or maybe a similar one?) down to

const CODE_BLOCK_R = /^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/

https://github.com/quantizor/markdown-to-jsx/blob/acd970dc7be8f2390ed916fe1b1cf0874a8534f6/index.tsx#L186C1-L187C1

being checked in

if (NON_PARAGRAPH_BLOCK_SYNTAXES.some(regex => regex.test(line))) {

Tester for catastrophic backtracing: https://regex101.com/r/85LH2r/1

For me, a suitable testcase in index.compiler.spec.tsx is

it('handles \\r\\n without crashing', () => {
  render(
    compiler(
      'Test \r\n                                                                                    \r\n Test'
    )
  )

  expect(root.innerHTML).toContain(`Test`)
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants