Giter Club home page Giter Club logo

Comments (9)

carhartl avatar carhartl commented on June 10, 2024

Yes, you'll have to add a \n in order to produce a line break in that string.

>> "foo\nbar"
"foo
bar"

Closing, as it's not really a problem with the plugin.

from jquery-cookie.

mborah avatar mborah commented on June 10, 2024

Sorry, but \n is not breaking my line in the output.

I tried with both:
In this string I want to break the Line like \n second line starts
In this string I want to break the Line like\nsecond line starts.

I don't know why it is not working for me.

from jquery-cookie.

FagnerMartinsBrack avatar FagnerMartinsBrack commented on June 10, 2024

@mborah The Line Feed (LF) is a control character (CTL) and therefore it is NOT allowed in the cookie value, as per RFC 6265

from jquery-cookie.

carhartl avatar carhartl commented on June 10, 2024

Ah, thanks @FagnerMartinsBrack 👍

So, a browser likely silently swallows that character.

from jquery-cookie.

FagnerMartinsBrack avatar FagnerMartinsBrack commented on June 10, 2024

I have no idea which browsers it breaks and how it breaks. When I was building the encoding tests, Safari and IE seemed to be the worst for invalid chars. Sometimes in Safari it ignored the value, and sometimes it ignored everything after the offending char or even prevented the whole cookie to be set.

Since the behavior is undefined, I like to assume that if you do something that goes against the RFC the browser will turn off your computer and it will never turn on again ;D

from jquery-cookie.

mborah avatar mborah commented on June 10, 2024

@FagnerMartinsBrack and @carhartl ... Thanks for your reply..
Same here, even for me sometimes in Mozilla it ignored the value, and sometimes it ignored everything or sometime shows the whole character including "\n". God Knows uffff....

So, finally what shud I do? Should I set two different cookies for different lines? Any suggestion would be helpful.

from jquery-cookie.

carhartl avatar carhartl commented on June 10, 2024

You could use say "__" to denote a line break, then, when reading a cookie, replace that again with a real line break using a converter function:

$.cookie("foo", "first__second");
$.cookie("foo", function (s) {
    return s.replace("__", "\n");
});

from jquery-cookie.

mborah avatar mborah commented on June 10, 2024

Thanks I will try with that.

from jquery-cookie.

FagnerMartinsBrack avatar FagnerMartinsBrack commented on June 10, 2024

Or you can post this issue in the new JavaScript Cookie project. I just ignored the control characters encode handling because I never thought someone would create a cookie with that. Supporting it costs unnecessary bytes to the codebase, but LF seems reasonable.

from jquery-cookie.

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.