Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix special character support. #111

Merged
merged 1 commit into from
Dec 20, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Library Documentation")

## Prerequisites

* PHP >= 5.2.1
* PHP >= 5.2.3
* The PHP JSON extension

## Reporting Issues
Expand Down
12 changes: 5 additions & 7 deletions Services/Twilio/Twiml.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,13 @@ public function __call($verb, array $args)
* want to break their existing code by turning their &'s into
* &
*
* So we end up with the following matrix:
* We also want to use numeric entities, not named entities so that we
* are fully compatible with XML
*
* We want & to turn into & before passing to addChild
* We want & to stay as & before passing to addChild
*
* The following line accomplishes the desired behavior.
* The following lines accomplishes the desired behavior.
*/
$normalized = htmlentities($noun, null, null, false);
//then escape it again
$decoded = html_entity_decode($noun, ENT_COMPAT, 'UTF-8');
$normalized = htmlspecialchars($decoded, ENT_COMPAT, 'UTF-8', false);
$child = empty($noun)
? $this->element->addChild(ucfirst($verb))
: $this->element->addChild(ucfirst($verb), $normalized);
Expand Down
24 changes: 24 additions & 0 deletions tests/TwimlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,30 @@ public function testSayConvienceMethod() {
$this->assertXmlStringEqualsXmlString($expected, $r);
}

public function testSayUTF8() {
$r = new Services_Twilio_Twiml();
$r->say("é tü & må");
$expected = '<Response><Say>'
. '&#xE9; t&#xFC; &amp; m&#xE5;</Say></Response>';
$this->assertXmlStringEqualsXmlString($expected, $r);
}

public function testSayNamedEntities() {
$r = new Services_Twilio_Twiml();
$r->say("&eacute; t&uuml; &amp; m&aring;");
$expected = '<Response><Say>'
. '&#xE9; t&#xFC; &amp; m&#xE5;</Say></Response>';
$this->assertXmlStringEqualsXmlString($expected, $r);
}

public function testSayNumericEntities() {
$r = new Services_Twilio_Twiml();
$r->say("&#xE9; t&#xFC; &amp; m&#xE5;");
$expected = '<Response><Say>'
. '&#xE9; t&#xFC; &amp; m&#xE5;</Say></Response>';
$this->assertXmlStringEqualsXmlString($expected, $r);
}

public function testPlayBasic() {
$r = new Services_Twilio_Twiml();
$r->play("hello-monkey.mp3");
Expand Down