From fa239448a2ecf95ffb19320c14d2d3a139d9fed1 Mon Sep 17 00:00:00 2001 From: Mauriac Date: Fri, 29 Apr 2022 11:27:57 +0000 Subject: [PATCH] Packages[core-data]: Accept numeric values for the "include" property in getQueryParts (#40570) * Packages[core-data]: Change "include" type in getQueryParts Convert the value of the parameter include into a string when it's a number. * Add some units test --- packages/core-data/src/queried-data/get-query-parts.js | 3 +++ packages/core-data/src/queried-data/test/get-query-parts.js | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/packages/core-data/src/queried-data/get-query-parts.js b/packages/core-data/src/queried-data/get-query-parts.js index 90ca024f80a41..b374465572866 100644 --- a/packages/core-data/src/queried-data/get-query-parts.js +++ b/packages/core-data/src/queried-data/get-query-parts.js @@ -80,6 +80,9 @@ export function getQueryParts( query ) { // Two requests with different include values cannot have same results. if ( key === 'include' ) { + if ( typeof value === 'number' ) { + value = value.toString(); + } parts.include = ( getNormalizedCommaSeparable( value ) ?? [] ).map( Number ); diff --git a/packages/core-data/src/queried-data/test/get-query-parts.js b/packages/core-data/src/queried-data/test/get-query-parts.js index b3ca692ad09f5..f355be21a439b 100644 --- a/packages/core-data/src/queried-data/test/get-query-parts.js +++ b/packages/core-data/src/queried-data/test/get-query-parts.js @@ -18,8 +18,12 @@ describe( 'getQueryParts', () => { } ); it( 'parses out `include` ID filtering', () => { + const first = getQueryParts( { include: '1' } ); + const second = getQueryParts( { include: 1 } ); const parts = getQueryParts( { include: [ 1 ] } ); + expect( first ).toEqual( second ); + expect( second ).toEqual( parts ); expect( parts ).toEqual( { context: 'default', page: 1,