Make WordPress Core

Opened 9 months ago

Last modified 9 months 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: REST API Keywords:
Focuses: Cc:


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 (2)

#1 @sabernhardt
9 months ago

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

#2 @TimothyBlynJacobs
9 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.

Note: See TracTickets for help on using tickets.