Should "http: //" be stored with the URL database entry?

There are several fields that the user can fill out, where they will enter the URL (their personal site, business site, favorite sites, etc.).

This is the only thing that they will enter this area.

So should I always highlight "http: //" so that it is consistent, and also reduce the possibility of broken links (ie, "http //")?

Just not sure what the best way to store urls.

+6
source share
2 answers

If there is a reason to sanitize your users ’input (security, size, speed, accuracy ...), do it.

But do not do it otherwise.

In fact, you get many times when you accept your data for data entry as is. They have their own typos or spelling errors, broken links, etc. Thus. So far this does not create a problem for you (i.e. you have no reason to disinfect it).

BTW - the sequence is controversial, because it will not change the data type, and you can easily check for "HTTP: //" and add or remove a useful function in your presentation layers with RESET if necessary.

+6
source

As far as I know, you really cannot name it β€œURL” without having a protocol part:

http://www.w3.org/Addressing/URL/url-spec.txt

I would not delete it.

However, if you really need the data to be consistent, it really depends on how the URL is actually entered into your application. If this application is similar to the browser, I would put that it can be assumed that it will be http: // in front, if it is not, for valid links.

+5
source

Source: https://habr.com/ru/post/895159/


All Articles