From 9ed989c30db53f89504db82e6d3a90166f69bcad Mon Sep 17 00:00:00 2001 From: ydah Date: Wed, 27 Nov 2024 19:53:18 +0900 Subject: [PATCH] Reject extra comma in array after keyword argument Fixes: https://github.com/ruby/prism/issues/3109 --- src/prism.c | 4 ++++ test/prism/errors/array_with_double_commas.txt | 3 +++ test/prism/errors/double_splat_with_double_commas.txt | 3 +++ 3 files changed, 10 insertions(+) create mode 100644 test/prism/errors/array_with_double_commas.txt create mode 100644 test/prism/errors/double_splat_with_double_commas.txt diff --git a/src/prism.c b/src/prism.c index b01f4df6dd..8c0dcb4e77 100644 --- a/src/prism.c +++ b/src/prism.c @@ -10874,6 +10874,10 @@ parser_lex(pm_parser_t *parser) { // , case ',': + if ((parser->previous.type == PM_TOKEN_COMMA) && (parser->enclosure_nesting > 0)) { + PM_PARSER_ERR_TOKEN_FORMAT(parser, parser->current, PM_ERR_ARRAY_TERM, pm_token_type_human(parser->current.type)); + } + lex_state_set(parser, PM_LEX_STATE_BEG | PM_LEX_STATE_LABEL); LEX(PM_TOKEN_COMMA); diff --git a/test/prism/errors/array_with_double_commas.txt b/test/prism/errors/array_with_double_commas.txt new file mode 100644 index 0000000000..7c971103f6 --- /dev/null +++ b/test/prism/errors/array_with_double_commas.txt @@ -0,0 +1,3 @@ +[a:1,,] + ^ unexpected ','; expected a `]` to close the array + diff --git a/test/prism/errors/double_splat_with_double_commas.txt b/test/prism/errors/double_splat_with_double_commas.txt new file mode 100644 index 0000000000..27873b7fac --- /dev/null +++ b/test/prism/errors/double_splat_with_double_commas.txt @@ -0,0 +1,3 @@ +[**a,,] + ^ unexpected ','; expected a `]` to close the array +