Skip to content

Commit

Permalink
escape utf8 fancy quotes from js api output
Browse files Browse the repository at this point in the history
otherwise iconv will convert them into plain quotes and hence break the
JS output.

Fixes #1218
  • Loading branch information
struan committed Feb 20, 2017
1 parent 8084364 commit 0d602d2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/AcceptApiTest.php
Expand Up @@ -54,6 +54,7 @@ public function testGetConstituencies() {
{"name":"Amber Valley"},
{"name":"Belfast West"},
{"name":"Cities of London and Westminster"}
{"name":"Cities of \"London\" and Westminster"}
]');
}

Expand Down
7 changes: 7 additions & 0 deletions tests/_fixtures/api.xml
Expand Up @@ -63,6 +63,13 @@
<field name="to_date">9999-12-31</field>
<field name="cons_id">11</field>
</row>
<row>
<field name="name">Cities of ‶London″ and Westminster</field>
<field name="main_name">1</field>
<field name="from_date">1983-00-00</field>
<field name="to_date">9999-12-31</field>
<field name="cons_id">13</field>
</row>
</table_data>
<table_data name="editqueue">
</table_data>
Expand Down
4 changes: 2 additions & 2 deletions www/docs/api/api_functions.php
Expand Up @@ -324,8 +324,8 @@ function api_output_js($v, $level=0) {
$out = "null";
} elseif (is_string($v)) {
$out = '"' . str_replace(
array("\\",'"',"\n","\t","\r"),
array("\\\\",'\"','\n','\t','\r'), $v) . '"';
array("\\",'"',"\n","\t","\r", "", "", "", ""),
array("\\\\",'\"','\n','\t','\r', '\"', '\"', '\"', '\"'), $v) . '"';
} elseif (is_bool($v)) {
$out = $v ? 'true' : 'false';
} elseif (is_int($v) || is_float($v)) {
Expand Down

0 comments on commit 0d602d2

Please sign in to comment.