diff --git a/spec/std/regex_spec.cr b/spec/std/regex_spec.cr index f71684ef66bb..698ca17c9a7d 100644 --- a/spec/std/regex_spec.cr +++ b/spec/std/regex_spec.cr @@ -115,8 +115,8 @@ describe "Regex" do /([\w_\.@#\/\*])+/.match("\xFF\xFE") end {% else %} - if Regex::PCRE2.version_number < {10, 35} - pending! "Error in libpcre2 < 10.35" + if Regex::PCRE2.version_number < {10, 36} + pending! "Error in libpcre2 < 10.36" else /([\w_\.@#\/\*])+/.match("\xFF\xFE").should be_nil end @@ -154,7 +154,7 @@ describe "Regex" do end it "multibyte index" do - if Regex::Engine.version_number < {10, 34} + if Regex::Engine.version_number < {10, 36} expect_raises(ArgumentError, "bad offset into UTF string") do /foo/.match_at_byte_index("öfoo", 1) end @@ -246,7 +246,7 @@ describe "Regex" do end it "invalid codepoint" do - if Regex::Engine.version_number < {10, 34} + if Regex::Engine.version_number < {10, 36} expect_raises(ArgumentError, "UTF-8 error") do /foo/.matches?("f\x96o") end @@ -310,7 +310,7 @@ describe "Regex" do end it "multibyte index" do - if Regex::Engine.version_number < {10, 34} + if Regex::Engine.version_number < {10, 36} expect_raises(ArgumentError, "bad offset into UTF string") do /foo/.matches_at_byte_index?("öfoo", 1) end diff --git a/src/regex/pcre2.cr b/src/regex/pcre2.cr index 4bfa074f4289..6c64fa1d8e41 100644 --- a/src/regex/pcre2.cr +++ b/src/regex/pcre2.cr @@ -23,7 +23,9 @@ module Regex::PCRE2 # :nodoc: def initialize(*, _source @source : String, _options @options) options = pcre2_compile_options(options) | LibPCRE2::UTF | LibPCRE2::DUPNAMES | LibPCRE2::UCP - if PCRE2.version_number >= {10, 34} + # MATCH_INVALID_UTF was introduced in 10.34 but a bug that can lead to an + # infinite loop is only fixed in 10.36 (https://github.com/PCRE2Project/pcre2/commit/e0c6029a62db9c2161941ecdf459205382d4d379). + if PCRE2.version_number >= {10, 36} options |= LibPCRE2::MATCH_INVALID_UTF end @re = PCRE2.compile(source, options) do |error_message|