Try as much as you can not to store garbage in your database. If you can trim off leading or trailing spaces from a URL before inserting it into a database table, do it.
In the other hand, you could write a trigger in the table that does that before inserting the value.
Any solution can potentially be comprised of more that just one front end (one web front-end, one Android front-end, one iPhone front-end, etc.). So relying in "the app", assumming that no other front-end will ever, never exist to the same back-end is something we should not assume.
So my recommendation is try not to insert garbage into tables only to clean it before outputing it to the user. You could potentially end up writing space-stripping code in a whole lot of places when you output that value from DB instead of doing it in just before inserting.