[ruby-core:112048] [Ruby master Bug#19379] Regex: "end pattern with unmatched parenthesis" with Ruby 3.2 and interpolation

Issue #19379 has been reported by renchap (Renaud Chaput). ---------------------------------------- Bug #19379: Regex: "end pattern with unmatched parenthesis" with Ruby 3.2 and interpolation https://bugs.ruby-lang.org/issues/19379 * Author: renchap (Renaud Chaput) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin22] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- Sample code: ``` r2 = %r{#c-\w+/comment/[\w-]+} %r{https?://[^/]+#{r2}}x ``` This works with Ruby 3.1: ``` irb(main):001:0> r2 = %r{#c-\w+/comment/[\w-]+} irb(main):002:0> %r{https?://[^/]+#{r2}}x => /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x ``` But fails with Ruby 3.2.0: ``` irb(main):022:0> r2 = %r{#c-\w+/comment/[\w-]+} irb(main):023:0> %r{https?://[^/]+#{r2}}x (irb):23:in `<main>': end pattern with unmatched parenthesis: /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x (RegexpError) ``` But if I dont use interpolation, it works correctly: ``` irb(main):001:0> %r{https?://[^/]+#c-\w+/comment/[\w-]+}x => /https?:\/\/[^\/]+#c-\w+\/comment\/[\w-]+/x ``` -- https://bugs.ruby-lang.org/

Issue #19379 has been updated by znz (Kazuhiro NISHIYAMA). ``` % docker run --platform linux/amd64 --rm -it ghcr.io/ruby/all-ruby env ALL_RUBY_SINCE=ruby-3.0 ./all-ruby -e 'r=/#/;p /#{r}/x' ruby-3.0.0 /(?-mix:#)/x ... ruby-3.2.0-preview1 /(?-mix:#)/x ruby-3.2.0-preview2 -e:1:in `<main>': end pattern with unmatched parenthesis: /(?-mix:#)/x (RegexpError) exit 1 ... ruby-3.2.0 -e:1:in `<main>': end pattern with unmatched parenthesis: /(?-mix:#)/x (RegexpError) exit 1 ``` ---------------------------------------- Bug #19379: Regex: "end pattern with unmatched parenthesis" with Ruby 3.2 and interpolation https://bugs.ruby-lang.org/issues/19379#change-101501 * Author: renchap (Renaud Chaput) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin22] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- Sample code: ``` r2 = %r{#c-\w+/comment/[\w-]+} %r{https?://[^/]+#{r2}}x ``` This works with Ruby 3.1: ``` irb(main):001:0> r2 = %r{#c-\w+/comment/[\w-]+} irb(main):002:0> %r{https?://[^/]+#{r2}}x => /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x ``` But fails with Ruby 3.2.0: ``` irb(main):022:0> r2 = %r{#c-\w+/comment/[\w-]+} irb(main):023:0> %r{https?://[^/]+#{r2}}x (irb):23:in `<main>': end pattern with unmatched parenthesis: /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x (RegexpError) ``` But if I dont use interpolation, it works correctly: ``` irb(main):001:0> %r{https?://[^/]+#c-\w+/comment/[\w-]+}x => /https?:\/\/[^\/]+#c-\w+\/comment\/[\w-]+/x ``` -- https://bugs.ruby-lang.org/

Issue #19379 has been updated by znz (Kazuhiro NISHIYAMA). I think minimal case is `/(?-x:#)/x`. ---------------------------------------- Bug #19379: Regex: "end pattern with unmatched parenthesis" with Ruby 3.2 and interpolation https://bugs.ruby-lang.org/issues/19379#change-101502 * Author: renchap (Renaud Chaput) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin22] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- Sample code: ``` r2 = %r{#c-\w+/comment/[\w-]+} %r{https?://[^/]+#{r2}}x ``` This works with Ruby 3.1: ``` irb(main):001:0> r2 = %r{#c-\w+/comment/[\w-]+} irb(main):002:0> %r{https?://[^/]+#{r2}}x => /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x ``` But fails with Ruby 3.2.0: ``` irb(main):022:0> r2 = %r{#c-\w+/comment/[\w-]+} irb(main):023:0> %r{https?://[^/]+#{r2}}x (irb):23:in `<main>': end pattern with unmatched parenthesis: /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x (RegexpError) ``` But if I dont use interpolation, it works correctly: ``` irb(main):001:0> %r{https?://[^/]+#c-\w+/comment/[\w-]+}x => /https?:\/\/[^\/]+#c-\w+\/comment\/[\w-]+/x ``` -- https://bugs.ruby-lang.org/

Issue #19379 has been updated by znz (Kazuhiro NISHIYAMA). Assignee set to make_now_just (Hiroya Fujinami) ---------------------------------------- Bug #19379: Regex: "end pattern with unmatched parenthesis" with Ruby 3.2 and interpolation https://bugs.ruby-lang.org/issues/19379#change-101503 * Author: renchap (Renaud Chaput) * Status: Open * Priority: Normal * Assignee: make_now_just (Hiroya Fujinami) * ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin22] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- Sample code: ``` r2 = %r{#c-\w+/comment/[\w-]+} %r{https?://[^/]+#{r2}}x ``` This works with Ruby 3.1: ``` irb(main):001:0> r2 = %r{#c-\w+/comment/[\w-]+} irb(main):002:0> %r{https?://[^/]+#{r2}}x => /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x ``` But fails with Ruby 3.2.0: ``` irb(main):022:0> r2 = %r{#c-\w+/comment/[\w-]+} irb(main):023:0> %r{https?://[^/]+#{r2}}x (irb):23:in `<main>': end pattern with unmatched parenthesis: /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x (RegexpError) ``` But if I dont use interpolation, it works correctly: ``` irb(main):001:0> %r{https?://[^/]+#c-\w+/comment/[\w-]+}x => /https?:\/\/[^\/]+#c-\w+\/comment\/[\w-]+/x ``` -- https://bugs.ruby-lang.org/

Issue #19379 has been updated by mame (Yusuke Endoh). Assignee deleted (make_now_just (Hiroya Fujinami)) I wonder if this is due to #18294, not #19104. @jeremyevans0 What do you think? ---------------------------------------- Bug #19379: Regex: "end pattern with unmatched parenthesis" with Ruby 3.2 and interpolation https://bugs.ruby-lang.org/issues/19379#change-101508 * Author: renchap (Renaud Chaput) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin22] * Backport: 2.7: DONTNEED, 3.0: DONTNEED, 3.1: DONTNEED, 3.2: REQUIRED ---------------------------------------- Sample code: ``` r2 = %r{#c-\w+/comment/[\w-]+} %r{https?://[^/]+#{r2}}x ``` This works with Ruby 3.1: ``` irb(main):001:0> r2 = %r{#c-\w+/comment/[\w-]+} irb(main):002:0> %r{https?://[^/]+#{r2}}x => /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x ``` But fails with Ruby 3.2.0: ``` irb(main):022:0> r2 = %r{#c-\w+/comment/[\w-]+} irb(main):023:0> %r{https?://[^/]+#{r2}}x (irb):23:in `<main>': end pattern with unmatched parenthesis: /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x (RegexpError) ``` But if I dont use interpolation, it works correctly: ``` irb(main):001:0> %r{https?://[^/]+#c-\w+/comment/[\w-]+}x => /https?:\/\/[^\/]+#c-\w+\/comment\/[\w-]+/x ``` -- https://bugs.ruby-lang.org/

Issue #19379 has been updated by jeremyevans0 (Jeremy Evans). mame (Yusuke Endoh) wrote in #note-5:
I wonder if this is due to #18294, not #19104. @jeremyevans0 What do you think?
I agree. #18294 doesn't handle `/(?-x:...)/` inside an extended regular expression as non-extended syntax. I'll see if I can fix it today. ---------------------------------------- Bug #19379: Regex: "end pattern with unmatched parenthesis" with Ruby 3.2 and interpolation https://bugs.ruby-lang.org/issues/19379#change-101524 * Author: renchap (Renaud Chaput) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin22] * Backport: 2.7: DONTNEED, 3.0: DONTNEED, 3.1: DONTNEED, 3.2: REQUIRED ---------------------------------------- Sample code: ``` r2 = %r{#c-\w+/comment/[\w-]+} %r{https?://[^/]+#{r2}}x ``` This works with Ruby 3.1: ``` irb(main):001:0> r2 = %r{#c-\w+/comment/[\w-]+} irb(main):002:0> %r{https?://[^/]+#{r2}}x => /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x ``` But fails with Ruby 3.2.0: ``` irb(main):022:0> r2 = %r{#c-\w+/comment/[\w-]+} irb(main):023:0> %r{https?://[^/]+#{r2}}x (irb):23:in `<main>': end pattern with unmatched parenthesis: /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x (RegexpError) ``` But if I dont use interpolation, it works correctly: ``` irb(main):001:0> %r{https?://[^/]+#c-\w+/comment/[\w-]+}x => /https?:\/\/[^\/]+#c-\w+\/comment\/[\w-]+/x ``` -- https://bugs.ruby-lang.org/

Issue #19379 has been updated by jeremyevans0 (Jeremy Evans). jeremyevans0 (Jeremy Evans) wrote in #note-6:
mame (Yusuke Endoh) wrote in #note-5:
I wonder if this is due to #18294, not #19104. @jeremyevans0 What do you think?
I agree. #18294 doesn't handle `/(?-x:...)/` inside an extended regular expression as non-extended syntax. I'll see if I can fix it today.
Should be fixed by https://github.com/ruby/ruby/pull/7192 ---------------------------------------- Bug #19379: Regex: "end pattern with unmatched parenthesis" with Ruby 3.2 and interpolation https://bugs.ruby-lang.org/issues/19379#change-101526 * Author: renchap (Renaud Chaput) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin22] * Backport: 2.7: DONTNEED, 3.0: DONTNEED, 3.1: DONTNEED, 3.2: REQUIRED ---------------------------------------- Sample code: ``` r2 = %r{#c-\w+/comment/[\w-]+} %r{https?://[^/]+#{r2}}x ``` This works with Ruby 3.1: ``` irb(main):001:0> r2 = %r{#c-\w+/comment/[\w-]+} irb(main):002:0> %r{https?://[^/]+#{r2}}x => /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x ``` But fails with Ruby 3.2.0: ``` irb(main):022:0> r2 = %r{#c-\w+/comment/[\w-]+} irb(main):023:0> %r{https?://[^/]+#{r2}}x (irb):23:in `<main>': end pattern with unmatched parenthesis: /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x (RegexpError) ``` But if I dont use interpolation, it works correctly: ``` irb(main):001:0> %r{https?://[^/]+#c-\w+/comment/[\w-]+}x => /https?:\/\/[^\/]+#c-\w+\/comment\/[\w-]+/x ``` -- https://bugs.ruby-lang.org/

Issue #19379 has been updated by naruse (Yui NARUSE). Backport changed from 2.7: DONTNEED, 3.0: DONTNEED, 3.1: DONTNEED, 3.2: REQUIRED to 2.7: DONTNEED, 3.0: DONTNEED, 3.1: DONTNEED, 3.2: DONE ruby_3_2 ca75332f46c39804e06cd37c2608cbdef0aebf05 merged revision(s) eccfc978fd6f65332eb70c9a46fbb4d5110bbe0a. ---------------------------------------- Bug #19379: Regex: "end pattern with unmatched parenthesis" with Ruby 3.2 and interpolation https://bugs.ruby-lang.org/issues/19379#change-101572 * Author: renchap (Renaud Chaput) * Status: Closed * Priority: Normal * ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin22] * Backport: 2.7: DONTNEED, 3.0: DONTNEED, 3.1: DONTNEED, 3.2: DONE ---------------------------------------- Sample code: ``` r2 = %r{#c-\w+/comment/[\w-]+} %r{https?://[^/]+#{r2}}x ``` This works with Ruby 3.1: ``` irb(main):001:0> r2 = %r{#c-\w+/comment/[\w-]+} irb(main):002:0> %r{https?://[^/]+#{r2}}x => /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x ``` But fails with Ruby 3.2.0: ``` irb(main):022:0> r2 = %r{#c-\w+/comment/[\w-]+} irb(main):023:0> %r{https?://[^/]+#{r2}}x (irb):23:in `<main>': end pattern with unmatched parenthesis: /https?:\/\/[^\/]+(?-mix:#c-\w+\/comment\/[\w-]+)/x (RegexpError) ``` But if I dont use interpolation, it works correctly: ``` irb(main):001:0> %r{https?://[^/]+#c-\w+/comment/[\w-]+}x => /https?:\/\/[^\/]+#c-\w+\/comment\/[\w-]+/x ``` -- https://bugs.ruby-lang.org/
participants (5)
-
jeremyevans0 (Jeremy Evans)
-
mame (Yusuke Endoh)
-
naruse (Yui NARUSE)
-
renchap (Renaud Chaput)
-
znz (Kazuhiro NISHIYAMA)