On Fri, 20 Aug 2021 13:46:39 GMT, Pavel Rappo <pra...@openjdk.org> wrote:
>> Ian Graves has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Couple of fixes > > test/jdk/java/util/regex/NegativeArraySize.java line 40: > >> 38: @Test >> 39: public static void testNegativeArraySize() { >> 40: assertThrows(OutOfMemoryError.class, () -> Pattern.compile("\\Q" >> + "a".repeat(42 + Integer.MAX_VALUE / 3))); > > One observation on this regex. Although the regex looks invalid because `\\Q` > misses the pairing `\\E`, it can still be compiled (with a reasonable number > of a's, of course). Moreover, the resulting pattern matches strings in a > surprising way: > > > jshell> Pattern.compile("\\Qaaa").matcher("aaa").matches() > $1 ==> true Maybe that behavior is expected after all. From "Mastering Regular Expressions" by Jeffrey E.F. Friedl, 3rd Edition, p. 136: > Literal-text span: `\Q...\E` > > First introduced with Perl, the special sequence `\Q...\E` turns off all > regex meta-characters between them, except for `\E` itself. (If the `\E` is > omitted, they are turned off until the end of the regex.) ------------- PR: https://git.openjdk.java.net/jdk/pull/5092