diff options
author | Adam Silverstein <adamsilverstein@git.wordpress.org> | 2020-10-29 18:30:41 +0000 |
---|---|---|
committer | Adam Silverstein <adamsilverstein@git.wordpress.org> | 2020-10-29 18:30:41 +0000 |
commit | ae33c9414c5840881c87f3c4f5a83a10ead78be9 (patch) | |
tree | 88955be0fbbdaaf5f2354ec6336fb4dd75c76686 /src/js/_enqueues/wp/api.js | |
parent | cbcc595974d5aaa025ca55625bf68ef286bd8b41 (diff) | |
download | wordpress-ae33c9414c5840881c87f3c4f5a83a10ead78be9.tar.gz wordpress-ae33c9414c5840881c87f3c4f5a83a10ead78be9.zip |
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
Diffstat (limited to 'src/js/_enqueues/wp/api.js')
-rw-r--r-- | src/js/_enqueues/wp/api.js | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/js/_enqueues/wp/api.js b/src/js/_enqueues/wp/api.js index b877a8df2c..b033a6f02b 100644 --- a/src/js/_enqueues/wp/api.js +++ b/src/js/_enqueues/wp/api.js @@ -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. |