Skip to content

Commit

Permalink
fix compatibility of last event ID with the latest version of the spec
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Apr 8, 2024
1 parent 489282d commit 20f4edc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Twig/MercureExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public function mercure($topics = null, array $options = []): string
}

if ('' !== ($options['lastEventId'] ?? '')) {
$url .= '&Last-Event-ID='.rawurlencode($options['lastEventId']);
$encodedLastEventId = rawurlencode($options['lastEventId']);
// Last-Event-ID is kept for compatibility with older versions of the protocol: https://mercure.rocks/docs/UPGRADE#0-14
$url .= "&lastEventID=$encodedLastEventId&Last-Event-ID=$encodedLastEventId";
}

if (
Expand Down
2 changes: 1 addition & 1 deletion tests/Twig/MercureExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ function (Update $u): string {
'lastEventId' => 'urn:uuid:13697bc5-e3c6-48cf-99c8-9d64c26f1a2f',
]);

$this->assertSame('https://example.com/.well-known/mercure?topic=https%3A%2F%2Ffoo%2Fbar&Last-Event-ID=urn%3Auuid%3A13697bc5-e3c6-48cf-99c8-9d64c26f1a2f', $url);
$this->assertSame('https://example.com/.well-known/mercure?topic=https%3A%2F%2Ffoo%2Fbar&lastEventID=urn%3Auuid%3A13697bc5-e3c6-48cf-99c8-9d64c26f1a2f&Last-Event-ID=urn%3Auuid%3A13697bc5-e3c6-48cf-99c8-9d64c26f1a2f', $url);
}
}

0 comments on commit 20f4edc

Please sign in to comment.