Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header values sometimes incorrectly treated as Dates #1

Closed
tombailey opened this issue Jul 15, 2023 · 1 comment
Closed

Header values sometimes incorrectly treated as Dates #1

tombailey opened this issue Jul 15, 2023 · 1 comment

Comments

@tombailey
Copy link

I noticed that some header values don't show correctly. For example, when I analyzed https://google.co.uk, the HeadersCard shows:

cache-control    1 January 2000
content-type    1 January 8859

I noticed the lambda function for the headers is returning the correct data:

{
  "date": ["Sat, 15 Jul 2023 06:17:25 GMT"],
  "expires": ["-1"],
  "cache-control": ["private, max-age=0"],
  "content-type": ["text/html; charset=ISO-8859-1"],
  ...
}

Digging deeper, I saw the Row component has both a title attribute and inner text for data. The HTML looks like this:

<div class="sc-cPiKLX iEeoJy">
  <span class="lbl">cache-control</span>
  <span class="val" title="private, max-age=0">1 January 2000</span>
</div>

The title is correct but the inner text is not.

It appears isValidDate(new Date(value)) of formatValue within the Row component is causing the problem:
https://github.com/Lissy93/web-check/blob/master/src/components/Form/Row.tsx#L72

Constructing a new Date with these header values produces a Date that is considered valid, hence the inner text is incorrectly formatted as a date.

console.log(new Date(["private, max-age=0"]));
// Sat Jan 01 2000 00:00:00 GMT+0900 (Japan Standard Time)

new Date('private, max-age=0')
// Sat Jan 01 2000 00:00:00 GMT+0900 (Japan Standard Time)

I created the following code sandbox to demonstrate the failing cases:
https://codesandbox.io/p/sandbox/unruffled-austin-lhypg6?file=%2Findex.test.ts%3A45%2C51

Perhaps something like js-http-date could help resolve the issue?

@Lissy93
Copy link
Owner

Lissy93 commented Jul 16, 2023

Thanks @tombailey for your detailed breakdown, this should be resolved now :)

@Lissy93 Lissy93 closed this as completed Jul 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants