Next-auth: A bit weird looking regex

Created on 10 Nov 2020  路  7Comments  路  Source: nextauthjs/next-auth

https://github.com/nextauthjs/next-auth/blob/8115a7c66cdb1d86b0d2a0d76b9aa33c2bfaa33b/src/lib/parse-url.js#L13

The regex /^http?:\/\// will match http:// but also htt://.
Is this really intended, or should the ? be removed on this line? (It is ofcourse needed later in the https? replace regex.)

question

All 7 comments

It probably misses an s before that question mark.

update: sorry, I see the purpose now. Maybe this could be an easier and more standard way of getting the protocol

Yes that sounds like a good idea

URL wasn't always available as a global in Node nor browsers so I would guess manually parsing the string is the best way to ensure the best compatibility without adding dependencies.

Ah ok, yeah sounds fair. but then it's just a matter of removing the ? in that specific line?

https://nodejs.org/api/url.html#url_class_url

If I understand this correctly, URL is supported since Node 10, which is the lowest supported node version anyway, so I think it is safe to use now. Am I wrong?

Good point! In browsers however, people who need to support Internet Explorer would have to include a polyfill.

@JohnProto Perhaps the original author had a reason to do it this way? Otherwise, I agree the ? doesn't seem to serve a purpose 馃

Next.js includes polyfills for IE11, I assume URL is no different. Or wouldn't that cut it, even though this package will always be used together with next?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Xetera picture Xetera  路  3Comments

ghoshnirmalya picture ghoshnirmalya  路  3Comments

MelMacaluso picture MelMacaluso  路  3Comments

ryanditjia picture ryanditjia  路  3Comments

simonbbyrne picture simonbbyrne  路  3Comments