Fixed my own XSS pull request to actually work

Sorry for the inconvenience, I appeared to have tested my latest pull request using the fix I used myself. So the pull request even gave errors.
This fixes the mistakes I made when I rewrote that code into the library.