Skip to content

Wordpress 5.5 breaks discoverability #476

Closed
@acburdine

Description

@acburdine

Ran 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions