Skip to content

Add Safari compatibility - #73

Merged
nightwatchcyber merged 1 commit into
securitytxt:masterfrom
joker314:fix-safari-date
Mar 18, 2021
Merged

nightwatchcyber merged 1 commit into
securitytxt:masterfrom
joker314:fix-safari-date

Conversation

@joker314

Copy link
Copy Markdown
Contributor

If a browser supports an HTML date input type, then the selected date will be presented to JS in the form YYYY-MM-DD. Safari does not have this UI, so instead the user is prompted to enter the date in that exact same format.

However, YYYY-MM-DD is not a format that the JavaScript Date constructor recognises in Safari (see Invalid Date in Safari on StackOverflow).

Before passing the date (whether it came from the user or the UI) to the Date constructor, this PR replaces all - symbols with / symbols. This is a format that Safari apparently recognises.

I have tested on Chrome to make sure it continues to work - I expect most modern browsers should support YYYY/MM/DD format.

Future work is to add validation to make sure that user inputs -- especially date inputs on Safari -- are actually valid dates. Part of that will be better error handling that will let the user know something went wrong. This is just a quick fix for Safari users but also any other browsers that don't support YYYY-MM-DD dates even if they do support the date picker UI.

@nightwatchcyber

Copy link
Copy Markdown
Contributor

Kind of wondering if there is a standard JS date library we can use

@nightwatchcyber
nightwatchcyber merged commit 6f77086 into securitytxt:master Mar 18, 2021
@joker314

Copy link
Copy Markdown
Contributor Author

Yeah, here are a few we may want to consider

@joker314
joker314 deleted the fix-safari-date branch March 18, 2021 00:38
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

Successfully merging this pull request may close these issues.

2 participants