regexr icon indicating copy to clipboard operation
regexr copied to clipboard

Rare freezing while trying this RegEx

Open PAPIONbit opened this issue 5 years ago • 3 comments
trafficstars

Hi First thanks for the great RegExr. I used that thousand times (then prayed for the creator ;)). Second :

Explaining the issue:

I was testing this expression:

/((?![^<]*>|[^<>]*<\/)(?!(\@\-)|(\@\_)|(\@\.)))((@\{[^\s\(\@\=\+\#\%\'\$\،\`\~\؛\?\؟\!\-\_\,\"\*\/\\\)]{1,16}\})|(@[^\s\(\@\=\+\#\%\'\,\?\؟\!\{\}\`\~\،\؛\"\:\*\/\\\)]{1,24}))(?<!\.)(?<!\-)(?<!\_)/ui

on your web-tool and using the replace like this : <a href="#" title="Mention him" onclick="chatme(this)">$0</a>

but any time i tried that, the page gone frozen.

  • It work well inside RegExr server-side and client-side just for a few moment. then the freeze will happen.
  • It work well in PHP 7 and (with a little change) in JavaScript like this in my web-app:

$txt=preg_replace(**THEREGEX**,'<a href="#" title="Mention him" onclick="chatme(this)">$0</a>', $txt);

Explain of pattern : Generally should work well for finding users mention inside a simple text file (Support all language characters with _ - . too) ((?![^<]*>|[^<>]*<\/) Ignoring inside of html tags (?!(\@\-)|(\@\_)|(\@\.))) Ignoring bad start after at-sign (@\{[^\s\(\@\=\+\#\%\'\$\،\`\~\؛\?\؟\!\-\_\,\"\*\/\\\)]{1,16}\})|(@[^\s\(\@\=\+\#\%\'\,\?\؟\!\{\}\`\~\،\؛\"\:\*\/\\\)]{1,24})) Finding IPs Inside of {} or any word attached to at-sign less than 24 character. (?<!\.)(?<!\-)(?<!\_) The found things should not finish with the _ - . too

  • RegExr Informed well about "negative look behind"

Using : Chrome Version 81.0.4044.129 (Official Build) (32-bit) - Win7 (32-bit)

Expecting:

A. RegExr don't freeze. Need debugging RegExr :) Or B. Stop User or RegExr engine before user input something that possible make an infinity loop (If debugging is not possible) Or C. Telling me if my pattern is not right or even crazy ;)

Best Regards

PAPIONbit avatar May 02 '20 17:05 PAPIONbit

I can see a crash, but it's slightly different from what your describing. The pattern you provided has some strange characters in it. They're causing a crash on rollover of certain parts of the pattern. For me I see whats looks like a backwards ? (I can't even select it in a text editor, so my system does not properly support it).

I made a small video that shows this in action. You can see when I reach that character the rollovers stop, and after that point my browser tab hangs, and I need to force quit it.

Tested on: macOS 10.15.4 Chrome 81.0.4044.129 (Official Build) (64-bit)

regexr-bug

wdamien avatar May 04 '20 17:05 wdamien

Works fine on Safari. Crashes on FF and Chrome. That, paired with the weird selection you can see right before it hangs in your gif (the grey selection box splits in half, which shouldn't be possible), makes me think it's probably a unicode bug in Chromium.

Given that this has never been reported before, I'm wondering if it's a recent injection.

gskinner avatar May 04 '20 17:05 gskinner

@wdamien Thanks for the analyse. @gskinner Thanks. Ye you are right. but the characters are so usual in Arabic / Persian / (So many other RTL Languages). They are Arabic/Persian comma, semicolons and RTL Question sign. I used them in JavaScript with something like this: .replace(/[\{\}\|\;\,\$\%\(\)\@\"\'\^\<\>\+\=\?\\\/\*\،\#\s\!\`\~\؛\؟\:]/g, "") and it work fine. So i think there should be a serious conflict between the way that RegExr analyse, and some codes of Unicode characters. For example maybe RegExr try to use their charCodeAt or something like that...

PAPIONbit avatar May 05 '20 03:05 PAPIONbit