From 0f1a7f7109388d0e002a0b746b324d142a9695ef Mon Sep 17 00:00:00 2001 From: Fritz Michael Gschwantner Date: Tue, 21 Feb 2023 09:23:06 +0100 Subject: [PATCH] remove trailing semicolon --- src/CSPBuilder.php | 2 +- test/BasicTest.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/CSPBuilder.php b/src/CSPBuilder.php index e5b6213..591aa3e 100644 --- a/src/CSPBuilder.php +++ b/src/CSPBuilder.php @@ -149,7 +149,7 @@ public function compile(): string $compiled []= 'upgrade-insecure-requests'; } - $this->compiled = implode('', $compiled); + $this->compiled = rtrim(implode('', $compiled), '; '); $this->needsCompile = false; return $this->compiled; } diff --git a/test/BasicTest.php b/test/BasicTest.php index 6a62790..20f1797 100644 --- a/test/BasicTest.php +++ b/test/BasicTest.php @@ -70,6 +70,23 @@ public function testBasicFromData() ); } + /** + * @throws \Exception + */ + public function testNoTrailingSemicolon() + { + $csp = (new CSPBuilder()) + ->setSelfAllowed('default-src', true) + ->addSource('img-src', 'ytimg.com') + ->disableOldBrowserSupport() + ; + + $this->assertEquals( + "default-src 'self'; img-src ytimg.com", + $csp->getCompiledHeader() + ); + } + /** * @throws \Exception */