nodejs-html-truncate icon indicating copy to clipboard operation
nodejs-html-truncate copied to clipboard

Truncate Regex Causes Infinite Loop

Open jbasdf opened this issue 8 years ago • 7 comments

This commit adds no value attributes to the truncation process but also introduces an infinite loop. Running this regex: KEY_VALUE_REGEX = '([\w|-]+\s*(=\s*"[^"]")?\s)*' on an iframe with attributes with and without values will result in the process freezing. For example, this bit of code will result in the process locking: <iframe width="560" height="315" src="//www.youtube.com/embed/eFGolAT2l6c" frameborder="0" allowfullscreen></iframe>

The specific line that freezes is 205: selfClose = SELF_CLOSE_REGEX.exec(result);

This error can be reproduced by executing that line of code, having set the pertinent values, on the command line. I've also written a test to demonstrate the problem on this branch:

https://github.com/huang47/nodejs-html-truncate/compare/master...jbasdf:locking_bug

jbasdf avatar Mar 16 '17 15:03 jbasdf

Wanted to bump this because its still an issue and another component I want to use relies on this library.

mdevine82 avatar Jan 25 '19 19:01 mdevine82

I'm actually experiencing this issue as well. A block of HTML I'm trying to truncate contains a Vimeo video embed and has attributes with no value so it's causing the process to lock up. :-(

kylefarris avatar Feb 05 '19 18:02 kylefarris

Hello @huang47, do you plan any updates? Thank you.

ex1st avatar Feb 28 '19 12:02 ex1st

Same issue, there is any solution?

thephucit avatar Aug 19 '19 04:08 thephucit

same.. any solution?

oferRounds avatar Jan 13 '20 10:01 oferRounds

Same issue. Seems like this was reverted in 2017 though? https://github.com/huang47/nodejs-html-truncate/commit/be300c7d85a465c8838333c0c4c7092c72ac425a

@huang47 @pakmanlh can you please publish a 1.2.3 version? 🙏

mhluska avatar Apr 09 '20 23:04 mhluska

And seems like it still does, hangs on HTML with 3 P and one nested IMG

P.S. Surprising ppl still trying to make gold from plumbum parse HTML with regex

nop1984 avatar Sep 07 '24 14:09 nop1984