Opened 4 years ago
Last modified 3 years 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)
#3
@
3 years 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.
#4
follow-up:
↓ 5
@
3 years ago
- Component changed from REST API to Plugins
- Focuses rest-api added
Related: #53808
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 benew RegExp(/^[^.\/]+(?:\/[^.\/]+)?$/);
which does compile successfully. Notice that the)?
was dropped.Cc: @kadamwhite.