Skip to content

Commit

Permalink
DX-2291 Added Encoding for Special Characters (#43)
Browse files Browse the repository at this point in the history
* DX-2291 Added Encoding for Special Characters

* added comment

* Fixed encoding and added test
  • Loading branch information
ckoegel authored Nov 9, 2021
1 parent ebaa322 commit 382e650
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Voice/Bxml/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 12 additions & 0 deletions tests/BxmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<?xml version="1.0" encoding="UTF-8"?><Response><SpeakSentence locale="en_US" gender="female" voice="susan">These characters cause problems &lt; &gt; &amp;</SpeakSentence></Response>';
$responseXml = $response->toBxml();
$this->assertEquals($expectedXml, $responseXml);
}

public function testSpeakSentenceSSML() {
$speakSentence = new BandwidthLib\Voice\Bxml\SpeakSentence('Hello, you have reached the home of <lang xml:lang="es-MX">Antonio Mendoza</lang>.Please leave a message.');
$response = new BandwidthLib\Voice\Bxml\Response();
Expand Down

0 comments on commit 382e650

Please sign in to comment.