Started adding slash commands, doesn't work though

This commit is contained in:
ION606
2022-09-26 15:41:20 +00:00
parent b6495eb886
commit ec4c1200d5
2214 changed files with 159174 additions and 42761 deletions
+83 -15
View File
@@ -20,8 +20,7 @@ exports.serialize = serialize;
* @private
*/
var decode = decodeURIComponent;
var encode = encodeURIComponent;
var __toString = Object.prototype.toString
/**
* RegExp to match field-content in RFC 7230 sec 3.2
@@ -52,31 +51,42 @@ function parse(str, options) {
var obj = {}
var opt = options || {};
var pairs = str.split(';')
var dec = opt.decode || decode;
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i];
var index = pair.indexOf('=')
var index = 0
while (index < str.length) {
var eqIdx = str.indexOf('=', index)
// skip things that don't look like key=value
if (index < 0) {
continue;
// no more cookie pairs
if (eqIdx === -1) {
break
}
var key = pair.substring(0, index).trim()
var endIdx = str.indexOf(';', index)
if (endIdx === -1) {
endIdx = str.length
} else if (endIdx < eqIdx) {
// backtrack on prior semicolon
index = str.lastIndexOf(';', eqIdx - 1) + 1
continue
}
var key = str.slice(index, eqIdx).trim()
// only assign once
if (undefined == obj[key]) {
var val = pair.substring(index + 1, pair.length).trim()
if (undefined === obj[key]) {
var val = str.slice(eqIdx + 1, endIdx).trim()
// quoted values
if (val[0] === '"') {
if (val.charCodeAt(0) === 0x22) {
val = val.slice(1, -1)
}
obj[key] = tryDecode(val, dec);
}
index = endIdx + 1
}
return obj;
@@ -145,11 +155,13 @@ function serialize(name, val, options) {
}
if (opt.expires) {
if (typeof opt.expires.toUTCString !== 'function') {
var expires = opt.expires
if (!isDate(expires) || isNaN(expires.valueOf())) {
throw new TypeError('option expires is invalid');
}
str += '; Expires=' + opt.expires.toUTCString();
str += '; Expires=' + expires.toUTCString()
}
if (opt.httpOnly) {
@@ -160,6 +172,26 @@ function serialize(name, val, options) {
str += '; Secure';
}
if (opt.priority) {
var priority = typeof opt.priority === 'string'
? opt.priority.toLowerCase()
: opt.priority
switch (priority) {
case 'low':
str += '; Priority=Low'
break
case 'medium':
str += '; Priority=Medium'
break
case 'high':
str += '; Priority=High'
break
default:
throw new TypeError('option priority is invalid')
}
}
if (opt.sameSite) {
var sameSite = typeof opt.sameSite === 'string'
? opt.sameSite.toLowerCase() : opt.sameSite;
@@ -185,6 +217,42 @@ function serialize(name, val, options) {
return str;
}
/**
* URL-decode string value. Optimized to skip native call when no %.
*
* @param {string} str
* @returns {string}
*/
function decode (str) {
return str.indexOf('%') !== -1
? decodeURIComponent(str)
: str
}
/**
* URL-encode value.
*
* @param {string} str
* @returns {string}
*/
function encode (val) {
return encodeURIComponent(val)
}
/**
* Determine if value is a Date.
*
* @param {*} val
* @private
*/
function isDate (val) {
return __toString.call(val) === '[object Date]' ||
val instanceof Date
}
/**
* Try decoding a string using a decoding function.
*