Fix handling of links containing underscores

Fixes #425. Added a test which covers this case. All tests pass.