Skip to content

Commit

Permalink
Don't use regex to trim whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Jan 27, 2023
1 parent b1bdb92 commit 560b2d8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ function parseCacheControl(header) {

// 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),
// the directive's value is considered invalid. Caches are encouraged to consider responses that have invalid freshness information to be stale
const parts = header.trim().split(/\s*,\s*/); // TODO: lame parsing
const parts = header.trim().split(/,/);
for (const part of parts) {
const [k, v] = part.split(/\s*=\s*/, 2);
cc[k] = v === undefined ? true : v.replace(/^"|"$/g, ''); // TODO: lame unquoting
const [k, v] = part.split(/=/, 2);
cc[k.trim()] = v === undefined ? true : v.trim().replace(/^"|"$/g, '');
}

return cc;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "http-cache-semantics",
"version": "4.1.0",
"version": "4.1.1",
"description": "Parses Cache-Control and other headers. Helps building correct HTTP caches and proxies",
"repository": "https://github.com/kornelski/http-cache-semantics.git",
"main": "index.js",
Expand Down

1 comment on commit 560b2d8

@zmzlois
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regex and semantic approved

Please sign in to comment.