From 508e08c1e108a035e89dfd882f52733bfcad84ab Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Mon, 21 Oct 2013 22:34:16 +0000 Subject: [PATCH] Properly transcode message body in API requests --- include/class.api.php | 13 ++++++++----- include/class.dynamic_forms.php | 2 +- include/class.forms.php | 4 ++-- include/class.xml.php | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/class.api.php b/include/class.api.php index 67f285527..6dec23efb 100644 --- a/include/class.api.php +++ b/include/class.api.php @@ -328,12 +328,19 @@ class ApiXmlDataParser extends XmlDataParser { $value = array( "body" => $value, "type" => "text/plain", - # TODO: Get encoding from root <xml> node + # Use encoding from root <xml> node ); } else { $value["body"] = $value[":text"]; unset($value[":text"]); } + if (isset($value['encoding'])) + $value['body'] = Format::utf8encode($value['body'], $value['encoding']); + if (!isset($value['type']) || $value['type'] != 'text/html') + $value = sprintf('<div style="white-space:pre-wrap">%s</div>', + Format::htmlchars($value['body'])); + else + $value = $value['body']; } else if ($key == "attachments") { if(!isset($value['file'][':text'])) $value = $value['file']; @@ -351,10 +358,6 @@ class ApiXmlDataParser extends XmlDataParser { } unset($value); - if(isset($current['message']) && $current['message']) - $current['message'] = sprintf('<div style="white-space:pre-wrap">%s</div>', - Format::htmlchars($current['message'])); - return $current; } } diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index e803235c8..79a092cbb 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -735,7 +735,7 @@ class SelectionField extends FormField { 'value'=>$value, 'list_id'=>$this->getListId())); } - return ($item) ? $item : $id; + return ($item) ? $item : $value; } function to_database($item) { diff --git a/include/class.forms.php b/include/class.forms.php index b51629bc5..6385f4190 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -166,8 +166,8 @@ class FormField { */ function getClean() { if (!isset($this->_clean)) { - $value = $this->getWidget()->value; - $this->_clean = $this->parse($value); + $this->_clean = (isset($this->value)) + ? $this->value : $this->parse($this->getWidget()->value); $this->validateEntry($this->_clean); } return $this->_clean; diff --git a/include/class.xml.php b/include/class.xml.php index 56baf4fbc..ff011eaa4 100644 --- a/include/class.xml.php +++ b/include/class.xml.php @@ -19,7 +19,7 @@ class XmlDataParser { function XmlDataParser() { - $this->parser = xml_parser_create(); + $this->parser = xml_parser_create('utf-8'); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, "startElement", "endElement"); xml_set_character_data_handler($this->parser, "content"); -- GitLab