REST API: JS Client - improve collection route construction for empty parents.

Fix an issue where the constructed path for hierarchical collections could contain a double slash ("//") when items contained empty parents, causing an error.

Props nicomollet.
Fixes #44745.


git-svn-id: https://develop.svn.wordpress.org/trunk@49390 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Adam Silverstein 2020-10-29 18:30:41 +00:00
parent cbcc595974
commit ae33c9414c
1 changed files with 5 additions and 2 deletions

View File

@ -1412,8 +1412,11 @@
// Function that returns a constructed url passed on the parent.
url: function() {
return routeModel.get( 'apiRoot' ) + routeModel.get( 'versionString' ) +
parentName + '/' + this.parent + '/' +
routeName;
parentName + '/' +
( ( _.isUndefined( this.parent ) || '' === this.parent ) ?
( _.isUndefined( this.get( 'parent_post' ) ) ? '' : this.get( 'parent_post' ) + '/' ) :
this.parent + '/' ) +
routeName;
},
// Specify the model that this collection contains.