Re: [mongodb-user] MongoDb 2.0.6. and HTML entities: data loss? Html entities break because Mongo converts all & to &

100 views
Skip to first unread message

Hannes Magnusson

unread,
Aug 10, 2012, 5:27:10 AM8/10/12
to mongod...@googlegroups.com
On Thu, Aug 9, 2012 at 9:44 PM, morningtime <mkoen...@gmail.com> wrote:
> Hi, I'm importing a UTF8 feed into MongoDb. It contains special characters
> such as á, í, ó, but also html encoded etities such as "&copy;" or "&reg;"
> etc.
>
> MongoDb 2.0.6 does this to me on a save() run throuhg PHP 5.4 with the
> official MongoDb driver:
>
> Source: "Bose&reg;"
> Saved in MongoDb as: "Bose&amp;reg;" (broken html!)
>
> Source: "Bose®"
> Saved in MongoDb as: "Bose®" (correct)
>
> Why does MongoDb do this? Why does it convert all & into &amp;, even for
> entities like &copy; -> &amp;copy; (broken html) ?


I cannot reproduce this..
$ cat entity.php
<?php
$m = new Mongo();

$m->test->entities->insert(array("v" => "Bose&reg;"), array("safe" => true));
var_dump($m->test->entities->findOne());
?>
$ php entity.php
array(2) {
["_id"]=>
object(MongoId)#6 (1) {
["$id"]=>
string(24) "5024d38e44415ed07b000000"
}
["v"]=>
string(9) "Bose&reg;"
}

How does your code look like?

-Hannes

Sam Millman

unread,
Aug 10, 2012, 5:50:02 AM8/10/12
to mongod...@googlegroups.com
Are you sure your not double encoding anywhere? I also cannot reproduce this, when I saw it on SO and here I tried quite hard to see if the PHP driver did this but I too failed to get a reproduction.


--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb

Reply all
Reply to author
Forward
0 new messages