Tweak normalization of $text

This adds a few extra checks and lets it pass through match.