]> git.kaiwu.me - njs.git/commit
Fixed RegExp.prototype.exec() with global regexp and unicode input.
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 18 Oct 2023 00:51:39 +0000 (17:51 -0700)
committerDmitry Volyntsev <xeioex@nginx.com>
Wed, 18 Oct 2023 00:51:39 +0000 (17:51 -0700)
commitea2adb73cdd60ff51b79b3f129c561aa5377df9c
treed307224952424f3b12f3296e48009dc14a700938
parentf26319b4566f9852e48f6660e14132968de699e6
Fixed RegExp.prototype.exec() with global regexp and unicode input.

Previously, when exactly 32 characters unicode string was provided and
the "lastIndex" value of "this" regexp was equal to 32 too, the
njs_string_utf8_offset() was called with invalid index argument (longer
than a size of the string).  As a result njs_string_utf8_offset()
returned garbage values.

This was manifested in the following ways:
1) InternalError: pcre2_match() failed: bad offset value

2) Very slow replace calls with global regexps, for
   example in expressions like: str.replace(/<re>/g).

This fixes #677 on Github.
src/njs_regexp.c
src/test/njs_unit_test.c