diff --git a/src/SimpleSAML/Error/AuthSource.php b/src/SimpleSAML/Error/AuthSource.php
index 1de3be5935c0768bce2ac4070a97918b7ee7025b..9470698e96ae028ee7664f3d694ec5589567a1f7 100644
--- a/src/SimpleSAML/Error/AuthSource.php
+++ b/src/SimpleSAML/Error/AuthSource.php
@@ -43,8 +43,8 @@ class AuthSource extends Error
         parent::__construct(
             [
                 'AUTHSOURCEERROR',
-                '%AUTHSOURCE%' => htmlspecialchars(var_export($this->authsource, true)),
-                '%REASON%' => htmlspecialchars(var_export($this->reason, true))
+                '%AUTHSOURCE%' => $this->authsource,
+                '%REASON%' => $this->reason
             ],
             $cause
         );
diff --git a/src/SimpleSAML/Error/MetadataNotFound.php b/src/SimpleSAML/Error/MetadataNotFound.php
index 0c18067601e0198e47a7b05a93e77111a5fd17a5..7cde1bda2595dc7351e0bd8b2992771b922858b6 100644
--- a/src/SimpleSAML/Error/MetadataNotFound.php
+++ b/src/SimpleSAML/Error/MetadataNotFound.php
@@ -24,7 +24,7 @@ class MetadataNotFound extends Error
         $this->includeTemplate = 'core:no_metadata.twig';
         parent::__construct([
                 'METADATANOTFOUND',
-                '%ENTITYID%' => htmlspecialchars(var_export($entityId, true))
+                '%ENTITYID%' => $entityId
         ]);
     }
 }
diff --git a/tests/modules/saml/src/Controller/ServiceProviderTest.php b/tests/modules/saml/src/Controller/ServiceProviderTest.php
index 7e50478845c815b3c13707add1cb2bcad3946530..5636553c5dbd8ca1905a08415d69fc9fdca40ecd 100644
--- a/tests/modules/saml/src/Controller/ServiceProviderTest.php
+++ b/tests/modules/saml/src/Controller/ServiceProviderTest.php
@@ -299,8 +299,7 @@ class ServiceProviderTest extends TestCase
         $c = new Controller\ServiceProvider($this->config, $this->session);
 
         $this->expectException(Error\MetadataNotFound::class);
-// Breaks PHP 8.1 tests
-//        $this->expectExceptionMessage("METADATANOTFOUND('%ENTITYID%' => '\'https://engine.test.surfconext.nl/authentication/idp/metadata\'')");
+        $this->expectExceptionMessage("METADATANOTFOUND('%ENTITYID%' => 'https://engine.test.surfconext.nl/authentication/idp/metadata')");
 
         $c->assertionConsumerService('phpunit');
     }
@@ -388,8 +387,7 @@ XML;
         $c = new Controller\ServiceProvider($this->config, $this->session);
 
         $this->expectException(Error\MetadataNotFound::class);
-// Breaks PHP 8.1 tests
-//        $this->expectExceptionMessage("METADATANOTFOUND('%ENTITYID%' => '\'https://engine.test.surfconext.nl/authentication/idp/metadata\'')");
+        $this->expectExceptionMessage("METADATANOTFOUND('%ENTITYID%' => 'TheIssuer')");
 
         $c->singleLogoutService('phpunit');
     }