[1.5.x] Simplified smart_urlquote and added some basic tests.

Backport of b70c371fc1f18ea0c43b503122df3f311afc7105 from master.