Skip to content

Commit 216a057

Browse files
committed
Add test for WP5.5 path regex and update pattern for proper matching
1 parent 7195506 commit 216a057

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/util/named-group-regexp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const pattern = [
1414
'[>\']',
1515
// Get everything up to the end of the capture group: this is the RegExp used
1616
// when matching URLs to this route, which we can use for validation purposes.
17-
'([^\\)]*(\\))?)\\??',
17+
'([^\\)]*(\\))?\\??)',
1818
// Capture group end
1919
'\\)',
2020
].join( '' );

tests/unit/lib/util/named-group-regexp.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,12 @@ describe( 'named PCRE group RegExp', () => {
4646
expect( result[ 2 ] ).toBe( '' );
4747
} );
4848

49+
it( 'correctly handles WP 5.5 plugins routes', () => {
50+
const path = '(?P<plugin>[^.\\/]+(?:\\/[^.\\/]+)?)';
51+
const result = path.match( namedGroupRE );
52+
expect( result ).not.toBeNull();
53+
expect( result[ 1 ] ).toBe( 'plugin' );
54+
expect( result[ 2 ] ).toBe( '[^.\\/]+(?:\\/[^.\\/]+)?' );
55+
} );
56+
4957
} );

0 commit comments

Comments
 (0)