Code Monkey home page Code Monkey logo

Comments (5)

vojtajina avatar vojtajina commented on May 22, 2024

This is a bit more complicated...
I don't think it's a problem of fromJson() neither angular's parser (which is behind the fromJson() method)
I hope, proper escaping should be responsibility of the creator of the source string (i.e. server side script, that generate json response)

Try this:
var jsonString = '{"one": "with "quote""}';
eval('(' + jsonString + ')');

You will surely get error, because when interpreter execute this:
var jsonString = '{"one" : "with "quote""}'
Variable jsonString contains a string like that: {"one" : "with "quote""}
Then, the parser has no chance to figure out which quotes should be escaped and which not...

The solution is to generate a valid json string like that:
var jsonString = '{"one" : "with "quote""}';
var orLikeThat = "{"one" : "with \"quote\""}";

from angular.js.

IgorMinar avatar IgorMinar commented on May 22, 2024

the serializer should absolutely be responsible for creating proper JSON. I came across the errors above when working on the personalLog demo app. The app serializes log messages into cookies when a new message is entered and deserializes these cookies on page load.

For some reason when I include quotes in my message, I get the errors above. I haven't had the time to investigate the issue further yet, but one way or another this is a symptom of a bug in angular.

We need to investigate this further.

from angular.js.

vojtajina avatar vojtajina commented on May 22, 2024

I was playing around with your personalLog demo app (btw pretty nice example !!!), I found the bug with removing wrong items (already fixed), but I was not able to simulate the problem with serialization, could add a test case for that ?

console.log(fromJson(toJson({a: 'aa \'s'})));
console.log(fromJson(toJson({a: 'aa "s'})));
console.log(fromJson(toJson({a: "aa 's"})));
console.log(fromJson(toJson({a: "aa \"s"})));

This works fine, so I still hope, the problem is not inside fromJson...

from angular.js.

IgorMinar avatar IgorMinar commented on May 22, 2024

you are right, I can't reproduce it any more. I guess I messed up something, but given the simplicity of data manipulation in the demo app I can't think of a way that would allow me to force cookieStore to persist incorrectly escaped strings. oh well.. I'll close this issue for now.

Thanks for investigating this.

from angular.js.

vojtajina avatar vojtajina commented on May 22, 2024

Sounds good, we have solved the issue without any single commit :-D

from angular.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.