danrevah / ngx-pipes

⚡️ Useful pipes for Angular with no external dependencies!
https://danrevah.gitbooks.io/angular-pipes
MIT License
1.6k stars 203 forks source link

bug: stripTags - regex recursive loop #255

Open gem85247 opened 1 year ago

gem85247 commented 1 year ago

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request

Current behavior

When passing the following through the "stripTags" pipe the browser crashes because of a regex recursive loop. Here is the breaking input:

• Damas Syrian (100 metres) < 1-minute walk
• Brazza cocktailbar (160 metres) < 2-minute walk
• Spanish Inn - Live Music Pub (400 metres) < 5-minute walk
• Bistro Mathilda (450 metres) < 5-minute walk

Expected behavior

Should return requested output without bricking the browser.

Minimal reproduction of the problem with instructions

STEPS TO REPRODUCE

Pass the breaking inpu (see above) and watch the browser/javascript engine crash/freeze.

MINIMAL DEMO

Just grabbed the regex from the source code and you can test the following snippet in any browser console:

console.log(`• Damas Syrian (100 metres) < 1-minute walk
• Brazza cocktailbar (160 metres) < 2-minute walk
• Spanish Inn - Live Music Pub (400 metres) < 5-minute walk
• Bistro Mathilda (450 metres) < 5-minute walk`.replace(/<(?:.|\s)*?>/g, ''));

Please tell us about your environment:

MacOs, WebStorm IDE, npm

gem85247 commented 1 year ago

The following Regex seems to fix the issue: /(<([^>]+)>)/gi. But I'm not a regex expert by any means 🙃