2

I have a form with user input fields for a manufacturer name and a product name that become a part of the URL

www.foo.bar/manufacturer_name/product_name/

Browsers will trim the trailing whitespace from manually entered urls but will encode them if they are not trailing.

If the user inputs:

manufacturer_name: WaynespaceEnterprisesspace

product_name: UtilityspaceBeltspace

The resulting URL in the browser would not be what the user inputted:

www.foo.bar/Wayne%20Enterprises%20/Utility%20Belt

This behavior from the browser seems like it would cause confusion to the user and that the application should trim trailing whitespaces from inputs on the users behalf. I worry it might cause confusion if they want the whitespace to really be there. Any input would be appreciated.

TLDR: Should I respect what the user inputted or should I clean up their input without telling them

Thanks!

0

Users generally aren't savvy and won't know the difference. If you need to reference the url easily by name you can't let them put in white spaces as you'd never know how many they are going to use. Definitely clean up their input.

0

Well, you could certainly disallow the use of spaces when they create these names, to make sure the URLs are cleaner to begin with - that's fairly common.

However if those are either too restrictive or not feasible, having URLs with spaces encoded as "%20"s is not that surprising to most savvy users. If you users are web literate enough to be reading the browser bar for clues as to their location, they probably won't be thrown by it; if not, they probably won't be using the URL to navigate by anyway.

On the whole, if user input is to be used as part of a URL path it is likely to need some "sanitizing." While %20 is not a problem, it can be a bit jarring to look at, and there's no reason not to clean it up for the user in that context (and as long as they know about it if they need to reference it later). If you go this route I'd suggest replacing a space with a non-intrusive character like an underscore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.