473,670 Members | 2,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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;exp ires=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.mozil la.org/en/docs/DOM:document.co okie#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 7111
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;exp ires=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.mozil la.org/en/docs/DOM:document.co okie#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;value s;

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;value s;

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;exp ires=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.mozil la.org/en/docs/DOM:document.co okie#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;value s;

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;value s;

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;exp ires=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.mozil la.org/en/docs/DOM:document.co okie#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(docum ent.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
3871
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 new site I goto seems to prompt me to store their cookie. The other is Pocket IE on Pocket PC 2002, with the cookies set to 'enabled'. My problem is that the cookies dont seem to be being written with my ASP. I dont get the prompt to store...
20
3543
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
5385
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 product the visitor can order by clicking one or more checkboxes. I made a form containing input with type "checkbox" like: <form> <input type="checkbox" name=ck id=ck
6
3039
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 cookie (say Response.Cookies ("TEST")) and you have a query string variable &test=x or &Test=x and you get Request.QueryString to parse the query string, the cookie that gets dropped matches the case of the query string, not what your code says. ...
11
1943
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 semicolons and sometimes not. Perhaps someone could enlighten me as to their proper usage in javascript. thank you
3
1977
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 browser stored the cookies as name values pairs with "." (Comma) instead of ";" (semi-colon) as delimiters! And this has created a problem for the Request.Cookies collection because (I believe) the microsoft cookies object has ";" as default delimiter....
5
1877
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 not understand why a new version of the framework that pretends to stay runinng for years until a new version, has to be not compliant with standards when the java platform already supports such standard.
3
4503
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 one of the string fields to be inserted. The string fields are inside single quotes in the INSERT command. With the semicolon in the string, the record is written correctly including the semicolon, but the identity is not returned. Without a...
1
2158
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 = function recalc(){deriv = 6;} .... then both the debugger and the lint report an error, saying there's
3
5892
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 presents an error. My question is: How to printf the semicolon ";" in C language?
0
8466
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8384
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8813
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8591
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8659
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7412
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4388
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.