IIRC this is a dangerous function to modify because our security code depends on it.  What's the motivation for this change?  I'm glad to see the tests below, but it looks like you're restricting what can be in the tag to alphanumeric, which means that non alpha characters (eg random UTF8) will fall out here and could cause us problems.  Unless there's a strong motivation to change it, I'd rather we left it as-is.  Again, this type of change should be documented in the bug with a clear example of what's wrong and what we're fixing.