Add test for invalid handling of namespace prefixes
Fix handling of invalid namespace prefixes

Fixes #861.

This is not actually complete, it still does not fix localName and
namespaceURI, but fixes a regression for now.