Skip to content

Commit

Permalink
support cookies with "=" in the value (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoow authored Mar 8, 2019
1 parent fc8d683 commit e5234f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion addon/services/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ export default Service.extend({
},

_filterDocumentCookies(unfilteredCookies) {
return unfilteredCookies.map((c) => c.split('='))
return unfilteredCookies.map((c) => {
let separatorIndex = c.indexOf('=');
return [c.substring(0, separatorIndex), c.substring(separatorIndex + 1)];
})
.filter((c) => c.length === 2 && isPresent(c[0]));
},

Expand Down
16 changes: 16 additions & 0 deletions tests/unit/services/cookies-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ describe('CookiesService', function() {

expect(this.subject().read(COOKIE_NAME)).to.eq(value);
});

it('works when the cookie contains a "="', function() {
let value = `${randomString()}=${randomString()}`;
document.cookie = `${COOKIE_NAME}=${value};`;
let afterRoundtrip = this.subject().read(COOKIE_NAME);

expect(afterRoundtrip).to.eq(value);
});
});

describe('writing a cookie', function() {
Expand Down Expand Up @@ -593,6 +601,14 @@ describe('CookiesService', function() {

expect(this.subject().read()).to.deep.equal({ [COOKIE_NAME]: writtenValue, aRequestCookie: requestValue });
});

it('works when the cookie contains a "="', function() {
let value = `${randomString()}=${randomString()}`;
this.subject().write(COOKIE_NAME, value);
let afterRoundtrip = this.subject().read(COOKIE_NAME);

expect(afterRoundtrip).to.eq(value);
});
});

describe('writing a cookie', function() {
Expand Down

0 comments on commit e5234f6

Please sign in to comment.