Quantcast
Channel: Peter of the Norse Thinks He’s Smarter than You
Viewing all articles
Browse latest Browse all 54

Gruber’s naive url finder

$
0
0

I’ve been playing with Gruber’s regex and found some faults. First, \w includes digits, so [\w\d] is redundant.

Second, and more troubling, is the use of [:punct:]. It works with PCRE, like he says, but not with anything else. So it doesn’t work with Javascript or Python. Also, Perl’s unicode is turned off by default. In that case [:punct:] only matches the 32 ASCII punctuation chars. So things like “www.example.com” are broken. And don’t tell me Gruber’s not going to use the interrobang. But Tinyarro.ws actually uses them. And some of the things covered by [:punct:]. There’s no good solution. (If you’ve got Tinyarro.ws’ previews (turned on by default) try http://➡.ws/@. It’s a redirect to http://➡.ws/닱. Someone forgot to turn on UTF-8 for the website.) I would rather [:punct:] was replaced with things that should be ignored. My suggestion is [^\s.,!?<>()[]:"“”'‘’«»].

Additional tests:

  • http://➡.ws/@
  • “www.example.com”

Update: Dammit! I forgot that most web slugs use hyphens. That’ll break under </code>[:punct:]</code>. Gruber uses underscores so that’s why he didn’t notice. Also, percent signs and hash marks won’t appear after an URL in real life. And what about sites that end with “.html”? It’s all mightily broken.


Viewing all articles
Browse latest Browse all 54

Trending Articles