Skip to content

Commit

Permalink
Enable PCRE UTF-8 validity string checks (#26731)
Browse files Browse the repository at this point in the history
Strings are no guaranteed to contain valid UTF-8, and PCRE documentation says
that the behavior is undefined in that case.
  • Loading branch information
nalimilan authored and JeffBezanson committed May 18, 2018
1 parent ecf2425 commit 627173b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/regex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

include("pcre.jl")

const DEFAULT_COMPILER_OPTS = PCRE.UTF | PCRE.NO_UTF_CHECK | PCRE.ALT_BSUX
const DEFAULT_MATCH_OPTS = PCRE.NO_UTF_CHECK
const DEFAULT_COMPILER_OPTS = PCRE.UTF | PCRE.ALT_BSUX
const DEFAULT_MATCH_OPTS = zero(UInt32)

mutable struct Regex
pattern::String
Expand Down
16 changes: 16 additions & 0 deletions test/regex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,19 @@ end

# Proper unicode handling
@test match(r"∀∀", "∀x∀∀∀").match == "∀∀"

@test_throws ErrorException match(r"a", "\xe2\x88") # 1 byte missing at end
@test_throws ErrorException match(r"a", "\xe2\x08\x80") # byte 2 top bits not 0x80
@test_throws ErrorException match(r"a", "\xf8\x89\x89\x80\x80") # 5-byte character is not allowed (RFC 3629)
@test_throws ErrorException match(r"a", "\xf4\x9f\xbf\xbf") # code points greater than 0x10ffff are not defined
@test_throws ErrorException match(r"a", "\Udfff") # code points 0xd800-0xdfff are not defined
@test_throws ErrorException match(r"a", "\xc0\x80") # overlong 2-byte sequence
@test_throws ErrorException match(r"a", "\xff") # illegal byte (0xfe or 0xff)

@test_throws ErrorException Regex("\xe2\x88") # 1 byte missing at end
@test_throws ErrorException Regex("\xe2\x08\x80") # byte 2 top bits not 0x80
@test_throws ErrorException Regex("\xf8\x89\x89\x80\x80") # 5-byte character is not allowed (RFC 3629)
@test_throws ErrorException Regex("\xf4\x9f\xbf\xbf") # code points greater than 0x10ffff are not defined
@test_throws ErrorException Regex("\Udfff") # code points 0xd800-0xdfff are not defined
@test_throws ErrorException Regex("\xc0\x80") # overlong 2-byte sequence
@test_throws ErrorException Regex("\xff") # illegal byte (0xfe or 0xff)

0 comments on commit 627173b

Please sign in to comment.