@edge-runtime/cookies
Advanced tools
Comparing version 4.0.1 to 4.0.2
@@ -114,2 +114,53 @@ "use strict"; | ||
} | ||
function splitCookiesString(cookiesString) { | ||
if (!cookiesString) | ||
return []; | ||
var cookiesStrings = []; | ||
var pos = 0; | ||
var start; | ||
var ch; | ||
var lastComma; | ||
var nextStart; | ||
var cookiesSeparatorFound; | ||
function skipWhitespace() { | ||
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) { | ||
pos += 1; | ||
} | ||
return pos < cookiesString.length; | ||
} | ||
function notSpecialChar() { | ||
ch = cookiesString.charAt(pos); | ||
return ch !== "=" && ch !== ";" && ch !== ","; | ||
} | ||
while (pos < cookiesString.length) { | ||
start = pos; | ||
cookiesSeparatorFound = false; | ||
while (skipWhitespace()) { | ||
ch = cookiesString.charAt(pos); | ||
if (ch === ",") { | ||
lastComma = pos; | ||
pos += 1; | ||
skipWhitespace(); | ||
nextStart = pos; | ||
while (pos < cookiesString.length && notSpecialChar()) { | ||
pos += 1; | ||
} | ||
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") { | ||
cookiesSeparatorFound = true; | ||
pos = nextStart; | ||
cookiesStrings.push(cookiesString.substring(start, lastComma)); | ||
start = pos; | ||
} else { | ||
pos = lastComma + 1; | ||
} | ||
} else { | ||
pos += 1; | ||
} | ||
} | ||
if (!cookiesSeparatorFound || pos >= cookiesString.length) { | ||
cookiesStrings.push(cookiesString.substring(start, cookiesString.length)); | ||
} | ||
} | ||
return cookiesStrings; | ||
} | ||
@@ -200,4 +251,6 @@ // src/request-cookies.ts | ||
this._parsed = /* @__PURE__ */ new Map(); | ||
var _a, _b, _c; | ||
this._headers = responseHeaders; | ||
const cookieStrings = responseHeaders.getSetCookie(); | ||
const setCookie = (_c = (_b = (_a = responseHeaders.getSetCookie) == null ? void 0 : _a.call(responseHeaders)) != null ? _b : responseHeaders.get("set-cookie")) != null ? _c : []; | ||
const cookieStrings = Array.isArray(setCookie) ? setCookie : splitCookiesString(setCookie); | ||
for (const cookieString of cookieStrings) { | ||
@@ -204,0 +257,0 @@ const parsed = parseSetCookie(cookieString); |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://edge-runtime.vercel.app/packages/cookies", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"main": "dist/index.js", | ||
@@ -32,3 +32,3 @@ "module": "dist/index.mjs", | ||
"@edge-runtime/format": "2.2.0", | ||
"@edge-runtime/jest-environment": "2.3.4" | ||
"@edge-runtime/jest-environment": "2.3.5" | ||
}, | ||
@@ -35,0 +35,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
46851
814