From e5234f627a30481a74468a68ea718f266d663634 Mon Sep 17 00:00:00 2001 From: Marco Otte-Witte Date: Fri, 8 Mar 2019 09:11:02 +0100 Subject: [PATCH] support cookies with "=" in the value (#201) --- addon/services/cookies.js | 5 ++++- tests/unit/services/cookies-test.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/addon/services/cookies.js b/addon/services/cookies.js index 55bbddfe..7cc5ecad 100644 --- a/addon/services/cookies.js +++ b/addon/services/cookies.js @@ -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])); }, diff --git a/tests/unit/services/cookies-test.js b/tests/unit/services/cookies-test.js index e053692f..eff4a1e2 100644 --- a/tests/unit/services/cookies-test.js +++ b/tests/unit/services/cookies-test.js @@ -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() { @@ -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() {