diff --git a/index.js b/index.js index d8765ee..558a1cf 100644 --- a/index.js +++ b/index.js @@ -102,14 +102,19 @@ function parse(str, options) { var index = 0; while (index < str.length) { - var endIdx = str.indexOf(';', index); - if (endIdx === -1) endIdx = str.length; + var eqIdx = str.indexOf('=', index); + + // no more cookie pairs + if (eqIdx === -1) { + break; + } - var eqIdx = index; - while (eqIdx < endIdx && str.charCodeAt(eqIdx) !== 0x3D /* = */) eqIdx++; + var endIdx = str.indexOf(';', index); - if (eqIdx === endIdx) { - index = endIdx + 1; + if (endIdx === -1) { + endIdx = str.length; + } else if (eqIdx > endIdx) { + index = str.lastIndexOf(';', eqIdx - 1) + 1; continue; }