Fixed cookies which contained unescaped '=' would not show up in cookie service.

This commit is contained in:
Misko Hevery 2011-03-09 21:03:11 -08:00
parent d304b0c3df
commit 26bad2bf87
3 changed files with 12 additions and 10 deletions

View file

@ -1,7 +1,8 @@
<a name="0.9.13"><a/> <a name="0.9.13"><a/>
# <angular/> 0.9.13 curdling-stare (in-progress) # # <angular/> 0.9.13 curdling-stare (in-progress) #
### Bug Fixes
- Fixed cookies which contained unescaped '=' would not show up in cookie service.

View file

@ -280,7 +280,7 @@ function Browser(window, document, body, XHR, $log) {
* @returns {Object} Hash of all cookies (if called without any parameter) * @returns {Object} Hash of all cookies (if called without any parameter)
*/ */
self.cookies = function (name, value) { self.cookies = function (name, value) {
var cookieLength, cookieArray, i, keyValue; var cookieLength, cookieArray, cookie, i, keyValue, index;
if (name) { if (name) {
if (value === _undefined) { if (value === _undefined) {
@ -307,9 +307,10 @@ function Browser(window, document, body, XHR, $log) {
lastCookies = {}; lastCookies = {};
for (i = 0; i < cookieArray.length; i++) { for (i = 0; i < cookieArray.length; i++) {
keyValue = cookieArray[i].split("="); cookie = cookieArray[i];
if (keyValue.length === 2) { //ignore nameless cookies index = cookie.indexOf('=');
lastCookies[unescape(keyValue[0])] = unescape(keyValue[1]); if (index > 0) { //ignore nameless cookies
lastCookies[unescape(cookie.substring(0, index))] = unescape(cookie.substring(index + 1));
} }
} }
} }

View file

@ -168,9 +168,9 @@ describe('browser', function(){
describe('put via cookies(cookieName, string)', function() { describe('put via cookies(cookieName, string)', function() {
it('should create and store a cookie', function() { it('should create and store a cookie', function() {
browser.cookies('cookieName', 'cookieValue'); browser.cookies('cookieName', 'cookie=Value');
expect(document.cookie).toMatch(/cookieName=cookieValue;? ?/); expect(document.cookie).toMatch(/cookieName=cookie%3DValue;? ?/);
expect(browser.cookies()).toEqual({'cookieName':'cookieValue'}); expect(browser.cookies()).toEqual({'cookieName':'cookie=Value'});
}); });
@ -263,8 +263,8 @@ describe('browser', function(){
it ('should return a value for an existing cookie', function() { it ('should return a value for an existing cookie', function() {
document.cookie = "foo=bar"; document.cookie = "foo=bar=baz";
expect(browser.cookies().foo).toEqual('bar'); expect(browser.cookies().foo).toEqual('bar=baz');
}); });