diff --git a/pkgs/racket-test-core/tests/racket/rx.rktl b/pkgs/racket-test-core/tests/racket/rx.rktl index 996cf00413..ee9e79c024 100644 --- a/pkgs/racket-test-core/tests/racket/rx.rktl +++ b/pkgs/racket-test-core/tests/racket/rx.rktl @@ -1800,6 +1800,20 @@ (err/rt-test (regexp "+" #f) (lambda (exn) (regexp-match? "`[+]' follows nothing in pattern" (exn-message exn)))) +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Make sure that negated patterns as literal strings are not recorded +;; as "must include this literal string" requirements + +(test '("aaa") regexp-match #rx"a*(?!b)" "aaaxy") +(test '("aaa") regexp-match #rx"a*(?integer #\a)))) +(test #f 'optimized (regexp-match #px"a*(?<=bc)" (make-bytes 100024 (char->integer #\a)))) + ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (report-errs) diff --git a/racket/src/racket/src/regexp.c b/racket/src/racket/src/regexp.c index 8354e3f10f..c5be06ac53 100644 --- a/racket/src/racket/src/regexp.c +++ b/racket/src/racket/src/regexp.c @@ -281,12 +281,16 @@ regcomp(char *expstr, rxpos exp, int explen, int pcre, Scheme_Object *handler) longest = 0; longest_is_ci = 0; len = 0; - for (; scan != 0; scan = regnext(scan)) { + for (; scan != 0; ) { int mscan = scan; while (1) { int mop; mop = rOP(mscan); - if (((mop == EXACTLY) || (mop == EXACTLY_CI)) + if ((mop == LOOKF) || (mop == LOOKBF)) { + /* skip over part that we don't want to match */ + mscan = mscan + rOPLEN(OPERAND(mscan)); + mscan = NEXT_OP(mscan); + } else if (((mop == EXACTLY) || (mop == EXACTLY_CI)) && rOPLEN(OPERAND(mscan)) >= len) { /* Skip regmust if it contains a null character: */ rxpos ls = OPSTR(OPERAND(mscan)); @@ -321,6 +325,13 @@ regcomp(char *expstr, rxpos exp, int explen, int pcre, Scheme_Object *handler) break; } prev_op = rOP(scan); + if ((prev_op == LOOKF) || (prev_op == LOOKBF)) { + /* skip over part that we don't want to match */ + scan = scan + rOPLEN(OPERAND(scan)); + scan = NEXT_OP(scan); + } else { + scan = regnext(scan); + } } if (longest) { r->regmust = longest;