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

View File

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