From b487a1836a87899f3c6803ea5865f715751a983a Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Tue, 1 Oct 2024 20:39:25 -0700 Subject: [PATCH] Undo = loop --- index.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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; }