diff options
author | ydah <[email protected]> | 2024-11-27 19:53:18 +0900 |
---|---|---|
committer | git <[email protected]> | 2024-12-02 18:39:49 +0000 |
commit | aa77bfd13ee183adde6bdc7812cfbb9580ea4b7a (patch) | |
tree | f6e4fc232998334b6ad3ad3da1ba89a0d0e32226 | |
parent | 90404ca46004e10e4e64e7b4e648d88ffcfb65ee (diff) |
[ruby/prism] Reject extra comma in array after keyword argument
Fixes: https://github.com/ruby/prism/issues/3109
https://github.com/ruby/prism/commit/9ed989c30d
-rw-r--r-- | prism/prism.c | 4 | ||||
-rw-r--r-- | test/prism/errors/array_with_double_commas.txt | 3 | ||||
-rw-r--r-- | test/prism/errors/double_splat_with_double_commas.txt | 3 |
3 files changed, 10 insertions, 0 deletions
diff --git a/prism/prism.c b/prism/prism.c index 83b6f7e00c..567c337054 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -10869,6 +10869,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 + |