Skip to content

Instantly share code, notes, and snippets.

@Meettya
Created July 1, 2024 09:09
Show Gist options
  • Save Meettya/14a1ea65af9393eff1ccb65fde7793db to your computer and use it in GitHub Desktop.
Save Meettya/14a1ea65af9393eff1ccb65fde7793db to your computer and use it in GitHub Desktop.
valid cookie name Re
/**
*
* token = 1*<any CHAR except CTLs or separators>
separators = "(" | ")" | "<" | ">" | "@"
| "," | ";" | ":" | "\" | <">
| "/" | "[" | "]" | "?" | "="
| "{" | "}" | SP | HT
*
*/
/*
CTL = <any US-ASCII control character
(octets 0 - 31) and DEL (127)>
*/
/*
SP = <US-ASCII SP, space (32)>
HT = <US-ASCII HT, horizontal-tab (9)>
<"> = <US-ASCII double-quote mark (34)>
*/
// CHAR = <any US-ASCII character (octets 0 - 127)>
const res = []
const exclude = [
"(",
")",
"<",
">",
"@",
"," ,
";" ,
":" ,
"\\" ,
"/" ,
"[" ,
"]" ,
"?" ,
"=",
"{" ,
"}"
];
for (let i=0; i <= 127; i++) {
if ((i <= 31) || i == 127 ) {
continue;
}
if (i == 32 || i == 34) {
continue;
}
if (exclude.includes(String.fromCharCode(i))) {
continue;
}
console.log(`${i}: ${String.fromCharCode(i)}`)
res.push(String.fromCharCode(i))
}
const resStr = res.join('');
const checkRe = /^[!#$%&'*+-.\da-z^_`|~]+$/i;
const matched = resStr.match(checkRe);
console.log(matched)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment