KJS regexp patch

Harri Porten porten at froglogic.com
Thu May 6 14:00:50 BST 2010


Hello Dmitriy,

On Thu, 6 May 2010, Dmitriy Taychenachev wrote:

> I have found two KJS bugs in regexp optimisation logic
> (regexp.cpp:sanitizePattern, introduced in r1088985):
> 1. The nonCapturing variable may become stale, since it is not refreshed in
> every loop iteration (for example in regexp "A(?:.|\s)*A(.|\s)*" the second
> group will be considered non-capturing, which is wrong.
> 2. The function may corrupt the regexp is the first group will be ignored as
> minimal, "tmp.append(np, previdx, idx-previdx+5);" will copy 5 characters
> forward to idx, while next statement "previdx = idx+6;" will drop six.
> Example: A((?:.|\s)*?)A((?:.|\s)+) will be rewriten to A((?:.|\s)?)A([\w\W]+)
> .
>
> The fixes are trivial. In the second case I have dropped else clause at all,
> since the pending characters would be copied by next rewrite (if any will
> happen), or by finishing code (if any already happened).

Great! What would be even greater: could you write up some small tests for the 
issues you found? They can be added to the RegExp.js file found in the 
khtmltests module:

  http://websvn.kde.org/trunk/tests/khtmltests/regression/tests/js/

You can easily execute the tests by opening testotherbrowser.html in 
Konqueror.

Harri.




More information about the kfm-devel mailing list