summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-08-01 11:21:14 -0400
committerTakashi Kokubun <takashikkbn@gmail.com>2023-08-16 17:47:32 -0700
commite56da35637cbb0107274047ea7ffb277d3ebddef (patch)
tree65e36c33f2e16b34ac923c942009cde0c8a888b4
parent4c4e75c0de961e5a838f52bb056ddae505722489 (diff)
[ruby/yarp] Handle invalid regexps more gracefully
https://github.com/ruby/yarp/commit/584a49f123
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/8226
-rw-r--r--yarp/yarp.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/yarp/yarp.c b/yarp/yarp.c
index fc0bd54d0f..2d719a62d6 100644
--- a/yarp/yarp.c
+++ b/yarp/yarp.c
@@ -12445,17 +12445,13 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t
yp_location_t *content_loc = &((yp_regular_expression_node_t *) node)->content_loc;
- YP_ATTRIBUTE_UNUSED bool captured_group_names =
- yp_regexp_named_capture_group_names(content_loc->start, (size_t) (content_loc->end - content_loc->start), &named_captures);
+ if (yp_regexp_named_capture_group_names(content_loc->start, (size_t) (content_loc->end - content_loc->start), &named_captures)) {
+ for (size_t index = 0; index < named_captures.length; index++) {
+ yp_string_t *name = &named_captures.strings[index];
+ assert(name->type == YP_STRING_SHARED);
- // We assert that the regex was successfully parsed
- assert(captured_group_names);
-
- for (size_t index = 0; index < named_captures.length; index++) {
- yp_string_t *name = &named_captures.strings[index];
- assert(name->type == YP_STRING_SHARED);
-
- yp_parser_local_add_location(parser, name->as.shared.start, name->as.shared.end);
+ yp_parser_local_add_location(parser, name->as.shared.start, name->as.shared.end);
+ }
}
yp_string_list_free(&named_captures);