capricorn86 / happy-dom

A JavaScript implementation of a web browser without its graphical user interface
MIT License
3.24k stars 194 forks source link

fix: [#1308] Fix a bug of multiple fallbacks of custom property #1309

Closed odanado closed 5 months ago

odanado commented 5 months ago

Fix: https://github.com/capricorn86/happy-dom/issues/1308

The previous code was incorrect in its use of RegExp.prototype.exec, and the regular expression matching was performed only once.

RegExp.prototype.exec is difficult to use correctly because it is a stateful API. I modified the logic using String.prototype.matchAll as described in MDN.

In addition, String.prototype.matchAll() helps to simplify matching multiple parts of a string (with capture groups) by allowing you to iterate over the matches. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#description

capricorn86 commented 5 months ago

Sorry @odanado, I was a bit fast. exec() won't work, so I changed it to this implementation using match() instead (which should also have good performance): https://github.com/capricorn86/happy-dom/pull/1312

Not sure why the unit tests passed in the PR :thinking: