Вопрос

Why Grails see URLs without http:// (like www.google.com) as invalid? Only http://google.com and http://www.google.com are ok. Is there any way to fix that ?

Это было полезно?

Решение

If you read RFC 1738 (Uniform Resource Locators), it is clear that the URL scheme (in your case, http://), is a full part of URLs. The scheme defines the meaning of the rest of the URL, and thus, can't be omitted. For instance http://www.google.com is definitely not the same ressource as https://www.google.com, and you should be aware of that when you save a link.

So URL like www.google.com are not valid, and Grails is right when it rejects them.

Fixing that should be easy if you know you expect an http URL:

new Object(url: 'http://' + url).save()

should do the trick.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top