Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regex: enable safe handling of invalid UTF-8 by default #39524

Merged
merged 2 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 42 additions & 15 deletions base/pcre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,45 +48,72 @@ end

# supported options for different use cases

# arguments to pcre2_compile
const COMPILE_MASK =
ALT_BSUX |
ALT_CIRCUMFLEX |
ALT_VERBNAMES |
ANCHORED |
# AUTO_CALLOUT |
CASELESS |
DOLLAR_ENDONLY |
DOTALL |
# DUPNAMES |
ENDANCHORED |
EXTENDED |
EXTENDED_MORE |
FIRSTLINE |
LITERAL |
MATCH_INVALID_UTF |
MATCH_UNSET_BACKREF |
MULTILINE |
NEWLINE_ANY |
NEWLINE_ANYCRLF |
NEWLINE_CR |
NEWLINE_CRLF |
NEWLINE_LF |
NEVER_BACKSLASH_C |
NEVER_UCP |
NEVER_UTF |
NO_AUTO_CAPTURE |
NO_AUTO_POSSESS |
NO_DOTSTAR_ANCHOR |
NO_START_OPTIMIZE |
NO_UTF_CHECK |
UCP |
UNGREEDY |
UTF |
UCP

USE_OFFSET_LIMIT |
UTF

# arguments to pcre2_set_newline
const COMPILE_NEWLINE_MASK = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seemed like someone wanted them in a list, so I kept them here

NEWLINE_CR,
NEWLINE_LF,
NEWLINE_CRLF,
NEWLINE_ANY,
NEWLINE_ANYCRLF,
NEWLINE_NUL)

# arguments to pcre2_set_compile_extra_options
const COMPILE_EXTRA_MASK =
EXTRA_ALLOW_SURROGATE_ESCAPES |
EXTRA_ALT_BSUX |
EXTRA_BAD_ESCAPE_IS_LITERAL |
EXTRA_ESCAPED_CR_IS_LF |
EXTRA_MATCH_LINE |
EXTRA_MATCH_WORD

# arguments to match
const EXECUTE_MASK =
NEWLINE_ANY |
NEWLINE_ANYCRLF |
NEWLINE_CR |
NEWLINE_CRLF |
NEWLINE_LF |
# ANCHORED |
# COPY_MATCHED_SUBJECT |
# ENDANCHORED |
NOTBOL |
NOTEMPTY |
NOTEMPTY_ATSTART |
NOTEOL |
# NO_JIT |
NO_START_OPTIMIZE |
NO_UTF_CHECK |
PARTIAL_HARD |
PARTIAL_SOFT


const OPTIONS_MASK = COMPILE_MASK | EXECUTE_MASK

const UNSET = ~Csize_t(0) # Indicates that an output vector element is unset

function info(regex::Ptr{Cvoid}, what::Integer, ::Type{T}) where T
Expand Down
2 changes: 1 addition & 1 deletion base/regex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

include("pcre.jl")

const DEFAULT_COMPILER_OPTS = PCRE.UTF | PCRE.NO_UTF_CHECK | PCRE.ALT_BSUX | PCRE.UCP
const DEFAULT_COMPILER_OPTS = PCRE.UTF | PCRE.MATCH_INVALID_UTF | PCRE.ALT_BSUX | PCRE.UCP
const DEFAULT_MATCH_OPTS = PCRE.NO_UTF_CHECK

"""
Expand Down