summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-01-16 11:25:43 +0900
committerNARUSE, Yui <naruse@airemix.jp>2020-01-16 15:26:28 +0900
commitdb4d136889afbf59e69efcfd495fd91cd401f378 (patch)
tree671483d357c34c6a5aad0fb089832a8bd6787a0d /re.c
parent8e8841f6bf58031a1fe5b0dbacb5a1fb442102df (diff)
`Regexp` in `MatchData` can be `nil`
`String#sub` with a string pattern defers creating a `Regexp` until `MatchData#regexp` creates a `Regexp` from the matched string. `Regexp#last_match(group_name)` accessed its content without creating the `Regexp` though. [Bug #16508]
Diffstat (limited to 're.c')
-rw-r--r--re.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/re.c b/re.c
index b15c3a07a8..9e9df700cf 100644
--- a/re.c
+++ b/re.c
@@ -1905,6 +1905,7 @@ match_captures(VALUE match)
static int
name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name, const char* name_end)
{
+ if (NIL_P(regexp)) return -1;
return onig_name_to_backref_number(RREGEXP_PTR(regexp),
(const unsigned char *)name, (const unsigned char *)name_end, regs);
}