Ignore trailing space in DOIs and trim URLs more generally in backend

Fixes #1539