WordPress.org

Make WordPress Core

Opened 12 months ago

Last modified 8 weeks ago

#51467 new defect (bug)

Plugins API endpoint regex breaks javascript parsing.

Reported by: nielsdeblaauw Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.5
Component: Plugins Keywords:
Focuses: rest-api Cc:

Description

The plugin endpoint /wp/v2/plugins/(?P<plugin>[^.\/]+(?:\/[^.\/]+)?) added in 5.5 breaks JavaScript parsing of the regular expression.

This can be tested by adding the following into the console:
new RegExp(/^[^.\/]+(?:\/[^.\/]+$/);

Which results in:
VM90:1 Uncaught SyntaxError: Invalid regular expression: /^[^.\/]+(?:\/[^.\/]+$/: Unterminated group at <anonymous>:1:1

One of the effects is that the node-wpapi library can no longer autodiscover WordPress endpoints: https://github.com/WP-API/node-wpapi/issues/476

Change History (6)

#1 @sabernhardt
12 months ago

  • Component changed from General to REST API
  • Focuses rest-api removed

#2 @TimothyBlynJacobs
12 months ago

  • Severity changed from major to normal

Thanks for the ticket @nielsdeblaauw!

Testing just the plain pattern [^.\/]+(?:\/[^.\/]+)? and ?<plugin>[^.\/]+(?:\/[^.\/]+)?). It appears to compile successfully for me in both Safari 14 and Node 12.

It looks like this might be an artifact of how node-wpapi handles transforming the route regex.

This, new RegExp(/^[^.\/]+(?:\/[^.\/]+$/); for instance should actually be new RegExp(/^[^.\/]+(?:\/[^.\/]+)?$/); which does compile successfully. Notice that the )? was dropped.

Cc: @kadamwhite.

#3 @ranjitp
8 weeks ago

I have got a Invalid regular expression. But when i removed the groupPattern ? '^' + groupPattern + '$' : component, 'i' in the line 81 from the file node_modules/wpapi/lib/route-tree.js. It is working fine. I have upgrade the WP. I got that error after that.

Last edited 8 weeks ago by SergeyBiryukov (previous) (diff)

#4 follow-up: @SergeyBiryukov
8 weeks ago

  • Component changed from REST API to Plugins
  • Focuses rest-api added

Related: #53808

#5 in reply to: ↑ 4 @ranjitp
8 weeks ago

Replying to SergeyBiryukov:

Related: #53808

Thanks for the response. But where should i change and what to change?

#6 @TimothyBlynJacobs
8 weeks ago

#53808 was marked as a duplicate.

Note: See TracTickets for help on using tickets.