[hibernate-issues] [Hibernate-JIRA] Commented: (HV-499) Add @URI validator to support relative URLs

Hardy Ferentschik (JIRA) noreply at atlassian.com
Wed Apr 11 04:33:50 EDT 2012


    [ https://hibernate.onjira.com/browse/HV-499?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46235#comment-46235 ] 

Hardy Ferentschik commented on HV-499:
--------------------------------------

{quote}
I think @URI and relative URLs are different kinds of things, probably we should handle them separately.
{quote}
Sure. I was not implying that we should mix them together. The usecase, however, was to support relative URLs and I want to explore different solutions.

{quote}
AFAIK relative URLs are only valid within the context of another URL, see we might add an attribute context() to @URL which specifies this context. We then could use the URL(URL context, String spec) constructor for validation (I think that's what you suggested to use protocol for).
{quote}

Right, the commit I was linking to was basically using the protocol string to create a context URL. During validation it then uses the _URL(URL context, String spec)_ constructor. I did not see the need for a new parameter _context_, but that's an additional possibility. 

{quote}
On the other hand I think one would always need an additional regular expression to specify the structure of the relative URL and I'm wondering what one actually gains by applying the @URL constraint to relative URLs at all? Maybe a simple @Pattern would suffice?
{quote}

+1 The biggest problem is that the URL constructor (the same for the URI constructor btw) don't (or very sparingly) validate the _spec_ string. The RFC places much more constraints on URI/URL. Using the _URL_ in _URLValidator_ is really more of a very simple solution for the most basic use cases. I expect that for more advanced use cases need to use the _regexp_ as well. We had long discussion whether _URLValidator_ should not purely be regular expression based however, it is hard to find an expression which really would be RFC compliant (if it even exit). For this reason we settled for the _URL_ + regexp approach. 

A _ at Pattern_ would definitely work, but by using _ at URL_ adds some more context information (it is not just any odd pattern the string has to match, it is a (part) of a URL).

The _regexpOnly_ flag might be worth exploring. We could collect a bunch of existing regular expressions and add them as constants to _ at URL_ for the user to chose from.

Or we just leave things as they are and they "use @Pattern" ;-)


> Add @URI validator to support relative URLs
> -------------------------------------------
>
>                 Key: HV-499
>                 URL: https://hibernate.onjira.com/browse/HV-499
>             Project: Hibernate Validator
>          Issue Type: New Feature
>          Components: validators
>    Affects Versions: 4.2.0.Final
>            Reporter: Ted Bergeron
>             Fix For: 4.3.0.CR1
>
>
> Should be trivial to leverage the @URL logic to allow for relative URI's.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list