{“name”:”c:\fakepath\event.xml”}
After using JSON.parse, the returned JSON object has value for "name"
as “c:fakpathevent.xml”. This is correct because the strings in JSON
payload are Javascript string and "\" is the escape character that
needs to be unescaped.
However, given another JSON payload
{“name”:”c:\\fakepath\\event.xml”}
It is expected that the resulting JSON object has "c:\fakepath
\event.xml" as value for "name". But JSONparse() returns something
different "c:\\fakepath\\event.xml".
This smells like a bug.
> --
> 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.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
> db.fakepath.save({"name":"c:\fakepath\event.xml"})
> db.fakepath.save({"name":"c:\\fakepath\\event.xml"})
> db.fakepath.find()
{ "_id" : ObjectId("4edce3eb0912f9e15972c252"), "name" : "c:
\fakepathevent.xml" }
{ "_id" : ObjectId("4edce3f60912f9e15972c253"), "name" : "c:\\fakepath\
\event.xml" }
> db.fakepath.find().forEach(function(doc) { print(doc.name.length); })1921
- this indicates to me that \f is one character, and \\ is also
treated as one character.
Weian, that looks wrong, but we need to know the driver language and
see some more code sample to be sure. I checked, and it doesn't look
like a ticket has been filed for the issue. Can you please do so as
Eliot suggested, or else get us a code fragment here?
FYI, JavaScript escape sequences can be looked up here:
http://www.javascriptkit.com/jsref/escapesequence.shtml .
u r right. The toString() of mongo's json object using
JSON.Serialize() and gets the escaped payload. That's not the in
memory java string.
It causes confusion when you use debugger.
wd
Thank you for filing the bug.
I am using Java, the code example is simple
String myJSONString = "{\"filename\":\"c:\\\\a\\\\d.txt\"}"'
JSONDBObject myObj = JSON.parse(payload);
System.out.println(myObj);
Weian
On 12月5日, 下午1时40分, Chris Westin <cwes...@yahoo.com> wrote:
> JJO, that's definitely wrong. I've filedhttps://jira.mongodb.org/browse/SERVER-4431
> > > This smells like a bug.- 隐藏被引用文字 -
>
> - 显示引用的文字 -
Second, I think you are overescaping the backslashes. I think you
really just want this:
String myJSONString = "{\"filename\":\"c:\\a\\d.txt\"}"' JSONDBObject
myObj = JSON.parse(payload); System.out.println(myObj);
Notice, in the first line, that the backslashes are only escaped once
instead of twice. For comparison, you are only escaping the double-
quotes once, so I believe you should escape your backslashes only once
as well.
JJO
As I mentioned in my other reply, the problem is mongo's JSON object.
It's toString() method used JSON.serialize().
As your second point, your understanding of java and JSON string
escaping is not correct. the java code you wrote
String myJSONString = "{\"filename\":\"c:\\a\\d.txt\"}"'
will results in the the following actual myJSOString in memory
{"filename" : "c:\a\d.txt"}
When you do a JSON.parse on this JSON string, the resulting JSON
object's filename attribute is (again in memory)
c:ad.txt
Which is not the desire result.
Try to write and run a test java program and see.
Regards!
Weian
On Dec 7, 7:44 am, JJO <j...@emberex.com> wrote:
> Two things:
> First, is the JSON class provided by the Java Mongo driver? That
> seems like it might be something in the JRE.
>
> Second, I think you are overescaping the backslashes. I think you
> really just want this:
>
> String myJSONString = "{\"filename\":\"c:\\a\\d.txt\"}"' JSONDBObject
> myObj =JSON.parse(payload); System.out.println(myObj);
> > > > > After usingJSON.parse, the returned JSON object has value for "name"