|
|
@@ -299,50 +299,36 @@ function MagicJS(scriptName = "MagicJS", logLevel = "INFO") {
|
|
|
}
|
|
|
|
|
|
parseSetCookies(cookieString) {
|
|
|
- const attribKeys = ['Expires', 'Max-Age', 'Domain', 'Path', 'HttpOnly', 'SameSite'];
|
|
|
- const parts = cookieString.split(';');
|
|
|
- let mainKey = null;
|
|
|
- const retDict = {};
|
|
|
- const retData = [];
|
|
|
- parts.forEach(part => {
|
|
|
- let pstr = part.trim();
|
|
|
- let aKey = null;
|
|
|
- let aValue = true;
|
|
|
-
|
|
|
- if (pstr.includes('=')) {
|
|
|
- let kvdata = pstr.split('=');
|
|
|
- aKey = kvdata[0].trim();
|
|
|
- aValue = kvdata[1].trim();
|
|
|
- } else {
|
|
|
- aKey = pstr;
|
|
|
- }
|
|
|
+ let tmpArr = setCookieStr.split(/,\s*/).map(cookieStr => {
|
|
|
+ const cookieParts = cookieStr.trim().split(/;\s*(?=[^=]+=[^;]*)/); // 使用正则表达式分割
|
|
|
+ const nameValue = cookieParts[0].split('=').map(part => part.trim());
|
|
|
+ const cookieObject = { name: nameValue[0], value: nameValue[1] };
|
|
|
+ // 解析其他属性
|
|
|
+ cookieParts.slice(1).forEach(attr => {
|
|
|
+ const [key, val] = attr.split('=').map(part => part.trim());
|
|
|
+ cookieObject[key] = val || true; // 如果没有值,则设置为 true
|
|
|
+ });
|
|
|
|
|
|
- if (attribKeys.includes(aKey)) {
|
|
|
- if (retDict[mainKey]) {
|
|
|
- retDict[mainKey][aKey] = aValue;
|
|
|
- let attribs = retDict[mainKey].attribs;
|
|
|
- attribs[aKey] = aValue;
|
|
|
+ return cookieObject;
|
|
|
+ });
|
|
|
+ let retData = [];
|
|
|
+ let i = 0;
|
|
|
+ while (i < tmpArr.length) {
|
|
|
+ const curItem = tmpArr[i];
|
|
|
+ retData.push(curItem);
|
|
|
+ if (curItem.Expires) {
|
|
|
+ const nextItem = tmpArr[i + 1];
|
|
|
+ if (nextItem) {
|
|
|
+ curItem.Expires = `${curItem.Expires},${nextItem.name}`;
|
|
|
}
|
|
|
+ i += 2;
|
|
|
} else {
|
|
|
- mainKey = aKey;
|
|
|
- let attribs = {};
|
|
|
- if (mainKey.includes(',')) {
|
|
|
- const keys = mainKey.split(',');
|
|
|
- keys.forEach(key => {
|
|
|
- const k = key.trim();
|
|
|
- if (attribKeys.includes(k)) {
|
|
|
- attribs[k] = true;
|
|
|
- } else {
|
|
|
- mainKey = k;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- retDict[mainKey] = { name: mainKey, value: aValue, attribs: attribs };
|
|
|
- retData.push(retDict[mainKey]);
|
|
|
+ i += 1;
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
return retData;
|
|
|
}
|
|
|
+
|
|
|
objToQueryStr(obj, encode) {
|
|
|
let str = '';
|
|
|
for (const key in obj) {
|