News for hackers. Stuff that matters.
Re:In search of the perfect URL validation regex (2010) by wolfgang42 on Saturday September 25, 2021 @05:43PM (#28656466)
I find that branchiness (and mutation of the variable) harder to follow. Personally, I’d just take “parse, don’t validate” to its logical conclusion and go for:

    const parseUrl = url => validateUrl(url) ? url : null;
    return parseUrl(url) || parseUrl('http://'+url) || null;

There are no comments on this comment yet.