Skip to content

Commit

Permalink
Merge pull request #2232 from herwinw/regexp_unicode_less_than_4_digits
Browse files Browse the repository at this point in the history
Raise a RegexpError if less than four digits are given for \uHHHH
  • Loading branch information
herwinw committed Sep 21, 2024
2 parents 3e85917 + bde3657 commit 7f2f316
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 1 addition & 3 deletions spec/core/regexp/shared/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,7 @@ def obj.to_int() ScratchPad.record(:called) end
end

it "raises a RegexpError if less than four digits are given for \\uHHHH" do
NATFIXME 'Update error message', exception: SpecFailedException, message: /but the message was/ do
-> { Regexp.send(@method, "\\" + "u304") }.should raise_error(RegexpError, Regexp.new(Regexp.escape("invalid Unicode escape: /\\u304/")))
end
-> { Regexp.send(@method, "\\" + "u304") }.should raise_error(RegexpError, Regexp.new(Regexp.escape("invalid Unicode escape: /\\u304/")))
end

it "raises a RegexpError if the \\u{} escape is empty" do
Expand Down
8 changes: 8 additions & 0 deletions src/regexp_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,15 @@ static String prepare_pattern_for_onigmo(Env *env, const StringObject *pattern,
default:
new_pattern.append_char('\\');
new_pattern.append_char('u');
if (!isxdigit(c))
env->raise("RegexpError", "invalid Unicode escape: /{}/", pattern->string());
new_pattern.append_char(c);
for (int i = 1; i < 4; i++) {
c = next_char();
if (!isxdigit(c))
env->raise("RegexpError", "invalid Unicode escape: /{}/", pattern->string());
new_pattern.append_char(c);
}
}

*fixed_encoding = true;
Expand Down

0 comments on commit 7f2f316

Please sign in to comment.