From 382e650d5cfc1b1faeb018cd9d21fa9399b12048 Mon Sep 17 00:00:00 2001
From: Cameron Koegel <53310569+ckoegel@users.noreply.github.com>
Date: Tue, 9 Nov 2021 17:00:29 -0500
Subject: [PATCH] DX-2291 Added Encoding for Special Characters (#43)
* DX-2291 Added Encoding for Special Characters
* added comment
* Fixed encoding and added test
---
src/Voice/Bxml/Response.php | 5 +++++
tests/BxmlTest.php | 12 ++++++++++++
2 files changed, 17 insertions(+)
diff --git a/src/Voice/Bxml/Response.php b/src/Voice/Bxml/Response.php
index ed24d75..35ede23 100644
--- a/src/Voice/Bxml/Response.php
+++ b/src/Voice/Bxml/Response.php
@@ -26,6 +26,11 @@ public function __construct() {
* @param Verb $verb The verb to add to the list
*/
public function addVerb($verb) {
+ foreach($verb as $key => $value) { // encodes any verb attributes of type string to avoid php character encoding bug
+ if(gettype($value) == "string") {
+ $verb->$key = htmlspecialchars($value, ENT_XML1, 'UTF-8');
+ }
+ }
array_push($this->verbs, $verb);
}
diff --git a/tests/BxmlTest.php b/tests/BxmlTest.php
index c1f0e49..0e5f301 100644
--- a/tests/BxmlTest.php
+++ b/tests/BxmlTest.php
@@ -178,6 +178,18 @@ public function testSpeakSentence() {
$this->assertEquals($expectedXml, $responseXml);
}
+ public function testSpeakSentenceEncode() {
+ $speakSentence = new BandwidthLib\Voice\Bxml\SpeakSentence("These characters cause problems < > &");
+ $speakSentence->voice("susan");
+ $speakSentence->locale("en_US");
+ $speakSentence->gender("female");
+ $response = new BandwidthLib\Voice\Bxml\Response();
+ $response->addVerb($speakSentence);
+ $expectedXml = 'These characters cause problems < > &';
+ $responseXml = $response->toBxml();
+ $this->assertEquals($expectedXml, $responseXml);
+ }
+
public function testSpeakSentenceSSML() {
$speakSentence = new BandwidthLib\Voice\Bxml\SpeakSentence('Hello, you have reached the home of Antonio Mendoza.Please leave a message.');
$response = new BandwidthLib\Voice\Bxml\Response();