From 816b9be323cdedb79015ef547abeb26b5fdbeba4 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Tue, 8 Oct 2019 09:30:28 -0700 Subject: [PATCH] Make ripper pass through unrecognized array format in hash patterns The purpose of the new_unique_key_hash is to check whether the hash has duplicate keys. If one of Ripper's on_* methods (e.g. on_label) has been overridden to use a different array format, Ripper should probably just pass through the array as is instead of assuming that the array represents duplicate keys. Fixes [Bug #16008] --- parse.y | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/parse.y b/parse.y index 2fd01ddb72..51aba59ddb 100644 --- a/parse.y +++ b/parse.y @@ -805,25 +805,26 @@ new_unique_key_hash(struct parser_params *p, VALUE ary, const YYLTYPE *loc) for (i = 0; i < len; i++) { VALUE key, a1, a2, a3; a1 = RARRAY_AREF(ary, i); - if (!(RB_TYPE_P(a1, T_ARRAY) && RARRAY_LEN(a1) == 2)) goto error; + if (!(RB_TYPE_P(a1, T_ARRAY) && RARRAY_LEN(a1) == 2)) goto invalid_format; a2 = RARRAY_AREF(a1, 0); - if (!RB_TYPE_P(a2, T_ARRAY)) goto error; + if (!RB_TYPE_P(a2, T_ARRAY)) goto invalid_format; switch (RARRAY_LEN(a2)) { case 2: /* "key": */ a3 = RARRAY_AREF(a2, 1); - if (!(RB_TYPE_P(a3, T_ARRAY) && RARRAY_LEN(a3) == 3)) goto error; + if (!(RB_TYPE_P(a3, T_ARRAY) && RARRAY_LEN(a3) == 3)) goto invalid_format; key = RARRAY_AREF(a3, 1); break; case 3: /* key: */ key = RARRAY_AREF(a2, 1); break; default: - goto error; + goto invalid_format; } - if (!RB_TYPE_P(key, T_STRING)) goto error; + if (!RB_TYPE_P(key, T_STRING)) goto invalid_format; if (st_lookup(tbl, (st_data_t)RSTRING_PTR(key), 0)) goto error; st_insert(tbl, (st_data_t)RSTRING_PTR(key), (st_data_t)ary); } + invalid_format: st_free_table(tbl); return ary; -- 2.23.0