Wordpress 5.5 breaks discoverability
See original GitHub issueRan into this after upgrading one of our wordpress sites to 5.5. This new version of wordpress adds a number of new API routes, including this one: /wp/v2/plugins/(?P<plugin>[^.\\/]+(?:\\/[^.\\/]+)?)
.
Currently, something in that regular expression is not playing nicely with the discoverability code, because whenever I point wpapi
at our wordpress 5.5 site, I get the following error:
SyntaxError: Invalid regular expression: /^[^.\/]+(?:\/[^.\/]+$/: Unterminated group
at new RegExp (<anonymous>)
at reduceRouteComponents (./node_modules/wpapi/lib/route-tree.js:86:3)
at Array.reduce (<anonymous>)
at reduceRouteTree (./node_modules/wpapi/lib/route-tree.js:185:18)
at Object.keys.reduce (./node_modules/wpapi/lib/util/object-reduce.js:25:20)
at Array.reduce (<anonymous>)
at module.exports (./node_modules/wpapi/lib/util/object-reduce.js:24:3)
at buildRouteTree (./node_modules/wpapi/lib/route-tree.js:203:9)
at WPAPI.bootstrap (./node_modules/wpapi/wpapi.js:349:23)
at new WPAPI (./node_modules/wpapi/wpapi.js:88:4)
Was able to reproduce it with this test:
const wpapi = require('wpapi');
async function test() {
await wpapi.discover('https://example-wordpress-55-site.com');
}
test().catch(console.error);
I added some logging in that reduceRouteComponents and confirmed that it’s the plugins url that’s messing things up.
Because discoverability is breaking, it falls back to assuming default routes, meaning none of our custom post types are currently usable via this package 😕
I’ll do my best to investigate further and open a PR, but wanted to open this issue in case anyone else runs into the same problem.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:15
- Comments:11
Top GitHub Comments
@kadamwhite Thanks very much for the release. I successfully tested the following using
wpapi 1.2.2
andWordPress 5.7.1
:wpapi
version1.2.2
has been released, which includes @socrates77’ change. Thank you for reporting this, and I am sorry to you all that I was lax in accepting and releasing this. I did adjust the RE slightly while rebasing that change into thev1
branch, so @kevinwhoffman @riddla @NielsdeBlaauw et al, if you still encounter this behavior after updating to v1.2.2, please @ me here with details.