Skip to content

Commit 76e86b0

Browse files
committed
Avoid matching segments after /amp/ in URL paths
1 parent 356e7c7 commit 76e86b0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/PairedAmpRouting.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public function detect_rewrite_endpoint( $should_parse_request ) {
327327
}
328328

329329
$amp_slug = amp_get_slug();
330-
$pattern = sprintf( '#(/%s)(?=/?(\?.*)?$)#', preg_quote( $amp_slug, '#' ) );
330+
$pattern = sprintf( ':/%s(?=/?(\?|$)):', preg_quote( $amp_slug, ':' ) );
331331

332332
// Detect and purge the AMP endpoint from the request.
333333
foreach ( [ 'REQUEST_URI', 'PATH_INFO' ] as $var ) {
@@ -873,8 +873,8 @@ public function has_paired_endpoint( $url = '' ) {
873873

874874
if ( ! $has_endpoint && ! empty( $parsed_url['path'] ) ) {
875875
$pattern = sprintf(
876-
'#/%s(/[^/^])?/?$#',
877-
preg_quote( $slug, '#' )
876+
':/%s/?$:',
877+
preg_quote( $slug, ':' )
878878
);
879879
if ( preg_match( $pattern, $parsed_url['path'] ) ) {
880880
$has_endpoint = true;
@@ -906,10 +906,10 @@ public function has_paired_endpoint( $url = '' ) {
906906
public function remove_paired_endpoint( $url ) {
907907
$slug = amp_get_slug();
908908

909-
// Strip endpoint, including /amp/, /amp/amp/, /amp/foo/.
909+
// Strip endpoint suffix.
910910
$non_amp_url = preg_replace(
911911
sprintf(
912-
':(/%s(/[^/?#]+)?)+(?=/?(\?|#|$)):',
912+
':/%s(?=/?(\?|#|$)):',
913913
preg_quote( $slug, ':' )
914914
),
915915
'',

0 commit comments

Comments
 (0)