Skip to content

Commit 560b2d8

Browse files
committed
Don't use regex to trim whitespace
1 parent b1bdb92 commit 560b2d8

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ function parseCacheControl(header) {
8080

8181
// TODO: When there is more than one value present for a given directive (e.g., two Expires header fields, multiple Cache-Control: max-age directives),
8282
// the directive's value is considered invalid. Caches are encouraged to consider responses that have invalid freshness information to be stale
83-
const parts = header.trim().split(/\s*,\s*/); // TODO: lame parsing
83+
const parts = header.trim().split(/,/);
8484
for (const part of parts) {
85-
const [k, v] = part.split(/\s*=\s*/, 2);
86-
cc[k] = v === undefined ? true : v.replace(/^"|"$/g, ''); // TODO: lame unquoting
85+
const [k, v] = part.split(/=/, 2);
86+
cc[k.trim()] = v === undefined ? true : v.trim().replace(/^"|"$/g, '');
8787
}
8888

8989
return cc;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "http-cache-semantics",
3-
"version": "4.1.0",
3+
"version": "4.1.1",
44
"description": "Parses Cache-Control and other headers. Helps building correct HTTP caches and proxies",
55
"repository": "https://github.com/kornelski/http-cache-semantics.git",
66
"main": "index.js",

0 commit comments

Comments
 (0)