From cfd44629416bf3c0d4142a3d68fb7a28480fa57f Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Mon, 3 Dec 2018 20:01:23 -0700 Subject: [PATCH] Allow nested objects in the `getResourceName()` identifier. --- plugins/woocommerce-admin/client/wc-api/utils.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/woocommerce-admin/client/wc-api/utils.js b/plugins/woocommerce-admin/client/wc-api/utils.js index eb4d148946e..c94419b153d 100644 --- a/plugins/woocommerce-admin/client/wc-api/utils.js +++ b/plugins/woocommerce-admin/client/wc-api/utils.js @@ -1,7 +1,21 @@ /** @format */ +/** + * External dependencies + */ +import { isObject } from 'lodash'; export function getResourceName( prefix, identifier ) { - const identifierString = JSON.stringify( identifier, Object.keys( identifier ).sort() ); + const keyList = []; + Object.keys( identifier ).forEach( key => { + keyList.push( key ); + + // whitelist nested object keys + if ( isObject( identifier[ key ] ) ) { + Array.prototype.push.apply( keyList, Object.keys( identifier[ key ] ) ); + } + } ); + + const identifierString = JSON.stringify( identifier, keyList.sort() ); return `${ prefix }:${ identifierString }`; }