Skip to content

Commit 7db2ce3

Browse files
authoredOct 18, 2023
Upgrade edge-runtime/cookies (#57021)
1 parent 40965eb commit 7db2ce3

File tree

4 files changed

+63
-10
lines changed

4 files changed

+63
-10
lines changed
 

‎packages/next/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
"@babel/traverse": "7.18.0",
136136
"@babel/types": "7.18.0",
137137
"@capsizecss/metrics": "1.1.0",
138-
"@edge-runtime/cookies": "4.0.1",
138+
"@edge-runtime/cookies": "4.0.2",
139139
"@edge-runtime/ponyfill": "2.4.1",
140140
"@edge-runtime/primitives": "4.0.2",
141141
"@hapi/accept": "5.0.2",

‎packages/next/src/compiled/@edge-runtime/cookies/index.js

+54-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,57 @@ function parsePriority(string) {
111111
string = string.toLowerCase();
112112
return PRIORITY.includes(string) ? string : void 0;
113113
}
114+
function splitCookiesString(cookiesString) {
115+
if (!cookiesString)
116+
return [];
117+
var cookiesStrings = [];
118+
var pos = 0;
119+
var start;
120+
var ch;
121+
var lastComma;
122+
var nextStart;
123+
var cookiesSeparatorFound;
124+
function skipWhitespace() {
125+
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
126+
pos += 1;
127+
}
128+
return pos < cookiesString.length;
129+
}
130+
function notSpecialChar() {
131+
ch = cookiesString.charAt(pos);
132+
return ch !== "=" && ch !== ";" && ch !== ",";
133+
}
134+
while (pos < cookiesString.length) {
135+
start = pos;
136+
cookiesSeparatorFound = false;
137+
while (skipWhitespace()) {
138+
ch = cookiesString.charAt(pos);
139+
if (ch === ",") {
140+
lastComma = pos;
141+
pos += 1;
142+
skipWhitespace();
143+
nextStart = pos;
144+
while (pos < cookiesString.length && notSpecialChar()) {
145+
pos += 1;
146+
}
147+
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
148+
cookiesSeparatorFound = true;
149+
pos = nextStart;
150+
cookiesStrings.push(cookiesString.substring(start, lastComma));
151+
start = pos;
152+
} else {
153+
pos = lastComma + 1;
154+
}
155+
} else {
156+
pos += 1;
157+
}
158+
}
159+
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
160+
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
161+
}
162+
}
163+
return cookiesStrings;
164+
}
114165

115166
// src/request-cookies.ts
116167
var RequestCookies = class {
@@ -196,8 +247,10 @@ var ResponseCookies = class {
196247
constructor(responseHeaders) {
197248
/** @internal */
198249
this._parsed = /* @__PURE__ */ new Map();
250+
var _a, _b, _c;
199251
this._headers = responseHeaders;
200-
const cookieStrings = responseHeaders.getSetCookie();
252+
const setCookie = (_c = (_b = (_a = responseHeaders.getSetCookie) == null ? void 0 : _a.call(responseHeaders)) != null ? _b : responseHeaders.get("set-cookie")) != null ? _c : [];
253+
const cookieStrings = Array.isArray(setCookie) ? setCookie : splitCookiesString(setCookie);
201254
for (const cookieString of cookieStrings) {
202255
const parsed = parseSetCookie(cookieString);
203256
if (parsed)
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"name":"@edge-runtime/cookies","version":"4.0.1","main":"./index.js","license":"MPL-2.0"}
1+
{"name":"@edge-runtime/cookies","version":"4.0.2","main":"./index.js","license":"MPL-2.0"}

‎pnpm-lock.yaml

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.