473,386 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Cookies: semicolon vs. semicolon-space

Hi,

These first three links say that when reading document.cookie the
name-value pairs are separated by semicolons and they show examples
like "name=value;expires=date" where there is clearly only a semicolon
separator.

<http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-1006298752-h2>
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-8747038>
<http://developer.mozilla.org/en/docs/DOM:document.cookie#Parameters>
The example on Microsoft's site shows that document.cookie.split('; ')
should be used to break up the cookies. This indicates there will
always be a semicolon and space separating the name-value pairs.

<http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/cookie.asp>
I tested Opera, Safari, Firefox, and IE and they all seem to use
semicolon-space.
So what is going on between the standards and the implementations? Are
the standards incorrectly stated? Should code be written to work both
ways or just the semicolon-space way?

Thank you,
Peter

Dec 10 '06 #1
3 7065
Daz

Peter Michaux wrote:
Hi,

These first three links say that when reading document.cookie the
name-value pairs are separated by semicolons and they show examples
like "name=value;expires=date" where there is clearly only a semicolon
separator.

<http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-1006298752-h2>
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-8747038>
<http://developer.mozilla.org/en/docs/DOM:document.cookie#Parameters>
The example on Microsoft's site shows that document.cookie.split('; ')
should be used to break up the cookies. This indicates there will
always be a semicolon and space separating the name-value pairs.

<http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/cookie.asp>
I tested Opera, Safari, Firefox, and IE and they all seem to use
semicolon-space.
So what is going on between the standards and the implementations? Are
the standards incorrectly stated? Should code be written to work both
ways or just the semicolon-space way?

Thank you,
Peter
Hi peter. As far as I am aware, you are able to store your data in a
cookie any way you want to.

I can only presume that using a space after the semi-colon will
increase the readability (not that you should need to look at the
contents as such), but more importantly, prevent problems when spliting
if one of the values themselves happens to contain a semi-colon.

For example: this is a value; this value contains a semi-colon;;
some;more;values;

In the code above, if you didn't use a space after the semi-colon, you
might end up with some weird results and get:
this is a value;
this value contains a semi-colon
some
more
values

Instead of:
this is a value;
this value contains a semi-colon;
some;more;values;

I hope this makes sense and that I am correct in my assumption.

Basically, I think it's more a question of good practise than a
standard. The is nothing stopping you using _)(- to delimit your cookie
values, although it doesn't look as pretty, takes up more space, and is
probably more difficult to work with.

Best wishes.

Daz.

Dec 10 '06 #2
Daz

Peter Michaux wrote:
Hi,

These first three links say that when reading document.cookie the
name-value pairs are separated by semicolons and they show examples
like "name=value;expires=date" where there is clearly only a semicolon
separator.

<http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-1006298752-h2>
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-8747038>
<http://developer.mozilla.org/en/docs/DOM:document.cookie#Parameters>
The example on Microsoft's site shows that document.cookie.split('; ')
should be used to break up the cookies. This indicates there will
always be a semicolon and space separating the name-value pairs.

<http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/cookie.asp>
I tested Opera, Safari, Firefox, and IE and they all seem to use
semicolon-space.
So what is going on between the standards and the implementations? Are
the standards incorrectly stated? Should code be written to work both
ways or just the semicolon-space way?

Thank you,
Peter
Hi peter. As far as I am aware, you are able to store your data in a
cookie any way you want to.

I can only presume that using a space after the semi-colon will
increase the readability (not that you should need to look at the
contents as such), but more importantly, prevent problems when spliting
if one of the values themselves happens to contain a semi-colon.

For example: this is a value; this value contains a semi-colon;;
some;more;values;

In the code above, if you didn't use a space after the semi-colon, you
might end up with some weird results and get:
this is a value
this value contains a semi-colon
some
more
values

Instead of:
this is a value
this value contains a semi-colon;
some;more;values;

I hope this makes sense and that I am correct in my assumption.

Basically, I think it's more a question of good practise than a
standard. The is nothing stopping you using _)(- to delimit your cookie
values, although it doesn't look as pretty, takes up more space, and is
probably more difficult to work with.

Best wishes.

Daz.

Dec 10 '06 #3
Peter Michaux wrote:
These first three links say that when reading document.cookie the
name-value pairs are separated by semicolons and they show examples
like "name=value;expires=date" where there is clearly only a semicolon
separator.

<http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-1006298752-h2>
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-8747038>
<http://developer.mozilla.org/en/docs/DOM:document.cookie#Parameters>
The second refers to RFC 2965, which does not require only a semicolon.
The example on Microsoft's site shows that document.cookie.split('; ')
should be used to break up the cookies. This indicates there will
always be a semicolon and space separating the name-value pairs.
[URI snipped]
I tested Opera, Safari, Firefox, and IE and they all seem to use
semicolon-space.

So what is going on between the standards and the implementations? Are
the standards incorrectly stated?
RFC 2965 allows optional white space between tokens. That is, spaces may
occur before or after the equals symbol that separates cookie names and
values, and before or after the semicolon that separates name/value pairs.
Should code be written to work both ways or just the semicolon-space way?
Both, in my opinion. Use a regular expression to search for, and obtain
the value of, the cookie:

new RegExp('(^|;)\\s*' + name
+ '\\s*=\\s*([^\\s;]+)').exec(document.cookie)

If the return value is null, there's no matching cookie. Otherwise, the
second capturing parentheses will contain the value. The value may not
contain spaces and the separating semicolon (if present) will be omitted.

Mike
Dec 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Brian Burgess | last post by:
Hi all, Anyone know of any special issues with storing cookies with ASP? I'm trying this with two browsers: One is IE 6.0 with cookies set to 'prompt'. This has been working properly as any...
20
by: Brian Burgess | last post by:
Hi all, Anyone know if this is possible? If so, on which page would the cookie be? .. On the page calling a function defined in the include file? thanks in advance.. -BB
4
by: Fred | last post by:
Hi, i know how to pass a value from Javascript to ASP with a hidden field into a form and submitting it, or with cookies, but here i have to pass a lot of data in an array. There is a list of...
6
by: Mark | last post by:
Hi... I've come across some weird bug with Response.Cookies. Or maybe it will be called "by design" but for the life of me I can't figure out what purpose it would serve. If you're setting a...
11
by: fritz | last post by:
Hi, When I look through the "javascript bible" I don't find any example scripts that have lines with ending semicolons. However when I peruse this newsgroup I find that sometimes there are ending...
3
by: Calvin Lai | last post by:
Hi all, I was developing an web application where the data in the client are stored in cookies using the Response.Cookies collection. However, I have found out that for some clients, their...
5
by: mauro | last post by:
it does not seem that the HttpCookie class is in compliance with the rfc 2109, it does not expose the optional comment attribute, even asp.net 2.0 beta 2 has this problem and frankly speaking I do...
3
by: Dan | last post by:
I'm writing a record from an asp.net page to SQL Server. After the insert I'm selecting @@identity to return the ID of the record that I just wrote. It worked fine until I typed a semicolon into...
1
by: Lawrence San | last post by:
According to a JavaScript debugger (Firebug), and to a JS lint, this is fine: function recalc(){deriv = 6;} But, if I've assigned the function to a variable like this: var bells =...
3
by: Ken | last post by:
Hi all, I want to printf a sentence with a semicolon, for examples: printf(" I like C language; You like C++ language."); But C compiler alway identify the semicolon as a end of a sentence and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.