WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.52k stars 4.21k forks source link

Invalid regular expression syntax error in route-tree when using WPAPI routes #59310

Closed gorm closed 8 months ago

gorm commented 8 months ago

Description

There seems to be an issue with using wpapi with a local wp-json.json file?

import WPAPI from 'wpapi';
import apiRootJSON from './wp-json.json';

var wp = new WPAPI({
  endpoint: 'http://localhost:8889/wp-json'
  routes: apiRootJSON.routes as any,
  nonce: 'xxxx',
});

The error I get in console:

Uncaught SyntaxError: Invalid regular expression: /^([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?$/i: Unterminated group (at route-tree.js:83:3)

Step-by-step reproduction instructions

  1. Setup test site using wp-env
  2. Download http://localhost:8889/wp-json (attached as file)
  3. Setup WPAPI with routes from json file

Screenshots, screen recording, code snippet

Screenshot

The wp-json.json file:

wp-json.json

Environment info

Using WordPress 6.4.3

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

t-hamano commented 8 months ago

Hi @gorm,

Based on the error log, this appears to be an issue with wadpi, not Gutenberg. This is probably where the error is occurring.:

https://github.com/WP-API/node-wpapi/blob/2cfe3ecff3b2f492224d67e0b25f5854fd5a81b8/lib/route-tree.js#L83

How about submitting an issue in the node-wpapi repository?

gorm commented 8 months ago

Yea, I just noticed it myself, that I was using the wrong API. Sorry for this. I will close.