UrlValidator

2005-07-28 Thread Marc Logemann

Hi,

can it be that UrlValidator from Commons-Validator doesnt validate URLs 
with localhost in it?


The following URL - http://localhost:8081/context/jsp/versand_1.jsp

breaks in isValidAuthority() within UrlValidator. It seems he tries to 
check for toplevel domain length and sees my localhost as a toplevel 
domain.


I am hoping i ve done something wrong because i would suspect that a 
UrlValidator validates this pretty straightforward URL.



--
regards
Marc Logemann
[blog] http://www.logemann.org
[busn] http://www.logentis.de

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: UrlValidator

2005-07-28 Thread Lindholm, Greg
I encountered this awhile back but didn't have time to investigate.
As a workaround I use the localhost IP address 127.0.0.1 but it
would be nice to get this fixed.
 

-Original Message-
From: Marc Logemann [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 28, 2005 8:33 AM
To: user@struts.apache.org
Subject: UrlValidator

Hi,

can it be that UrlValidator from Commons-Validator doesnt validate URLs 
with localhost in it?

The following URL - http://localhost:8081/context/jsp/versand_1.jsp

breaks in isValidAuthority() within UrlValidator. It seems he tries to 
check for toplevel domain length and sees my localhost as a toplevel 
domain.

I am hoping i ve done something wrong because i would suspect that a 
UrlValidator validates this pretty straightforward URL.


-- 

regards
Marc Logemann
[blog] http://www.logemann.org
[busn] http://www.logentis.de

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: UrlValidator

2005-07-28 Thread Marc Logemann

Hi,

if i have the time in the next days i will work on that, but where 
should i send a possible fix? struts-dev or to the commons-validator guys?




Lindholm, Greg wrote:

I encountered this awhile back but didn't have time to investigate.
As a workaround I use the localhost IP address 127.0.0.1 but it
would be nice to get this fixed.
 


-Original Message-
From: Marc Logemann [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 28, 2005 8:33 AM

To: user@struts.apache.org
Subject: UrlValidator

Hi,

can it be that UrlValidator from Commons-Validator doesnt validate URLs 
with localhost in it?


The following URL - http://localhost:8081/context/jsp/versand_1.jsp



--
regards
Marc Logemann
[blog] http://www.logemann.org
[busn] http://www.logentis.de

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: UrlValidator (why not use java.net.URL?)

2005-07-28 Thread Marc Logemann

Hi,

after looking into the code of UrlValidator and moreover looking into a 
similar class in Tapestry which is no longer active as it seems, i 
wonder why commons-validator UrlValidator is using Regex so much. 
Wouldnt it be enough to just use java.net.URL and let this class do the 
verification? Of course i am not quite sure how it deals non-schema URLs 
but for complete URLs to verifiy, its perhaps a better choice.


Perhaps this one is for the developer list but i try it here first ;-)




Lindholm, Greg wrote:

I encountered this awhile back but didn't have time to investigate.
As a workaround I use the localhost IP address 127.0.0.1 but it
would be nice to get this fixed.
 


-Original Message-
From: Marc Logemann [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 28, 2005 8:33 AM

To: user@struts.apache.org
Subject: UrlValidator

Hi,

can it be that UrlValidator from Commons-Validator doesnt validate URLs 
with localhost in it?


The following URL - http://localhost:8081/context/jsp/versand_1.jsp



--
regards
Marc Logemann
[blog] http://www.logemann.org
[busn] http://www.logentis.de


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: UrlValidator (why not use java.net.URL?)

2005-07-28 Thread Laurie Harper
I'd guess the reason is to make it easier to keep the client- and 
server-side validation in sync. java.net.URL is, obviously, not available 
to the client-side validation. The Commons Validator list is probably the 
right place to follow this up.


L.

Marc Logemann wrote:


Hi,

after looking into the code of UrlValidator and moreover looking into a 
similar class in Tapestry which is no longer active as it seems, i 
wonder why commons-validator UrlValidator is using Regex so much. 
Wouldnt it be enough to just use java.net.URL and let this class do the 
verification? Of course i am not quite sure how it deals non-schema URLs 
but for complete URLs to verifiy, its perhaps a better choice.


Perhaps this one is for the developer list but i try it here first ;-)




Lindholm, Greg wrote:


I encountered this awhile back but didn't have time to investigate.
As a workaround I use the localhost IP address 127.0.0.1 but it
would be nice to get this fixed.
 


-Original Message-
From: Marc Logemann [mailto:[EMAIL PROTECTED] Sent: Thursday, July 
28, 2005 8:33 AM

To: user@struts.apache.org
Subject: UrlValidator

Hi,

can it be that UrlValidator from Commons-Validator doesnt validate 
URLs with localhost in it?


The following URL - http://localhost:8081/context/jsp/versand_1.jsp







--
Laurie, Open Source advocate, Java geek and novice blogger:
http://www.holoweb.net/laurie


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: UrlValidator() takes options - but how?

2004-04-01 Thread Niall Pemberton
UrlValidator is not the class that is instantiated  by ValidatorAction
because it doesn't know anything about Struts resources - the Struts
FieldChecks.validateUrl() method calls commons GenericValidator which
instantiates the UrlValidator.

Rather than using the struts FieldChecks.validateUrl(), create you own
version which instantiates the url validator and picks up var values to
configure it. Something like:


field property=someUrl depends=myUrlValidator
  varvar-nameslashes/var-name
var-valuetrue/var-value
  /var
  varvar-namefragments/var-name
var-valuetrue/var-value
  /var
/field

   public static boolean validateUrl(Object bean,
ValidatorAction va, Field field,
ActionMessages errors,
HttpServletRequest request) {

String value = null;
if (isString(bean)) {
value = (String) bean;
} else {
value = ValidatorUtils.getValueAsString(bean,
field.getProperty());
}
int options = 0;

if (true.equals(field.getVarValue(slashes)))
 options += UrlValidator.ALLOW_2_SLASHES;

if (true.equals(field.getVarValue(fragments)))
 options += UrlValidator.ALLOW_2_SLASHES;

UrlValidator urlValidator = new UrlValidator(options);

if (!GenericValidator.isBlankOrNull(value) 
!urlValidator.isValid(value)) {
errors.add(field.getKey(), Resources.getActionMessage(request,
va, field));
return false;
} else {
return true;
}
}

- Original Message - 
From: Adam Hardy [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, April 01, 2004 12:17 PM
Subject: UrlValidator() takes options - but how?



 In UrlValidator() in the validator package, one can set various options
 upon instantiation, such as ALLOW_2_SLASHES or NO_FRAGMENTS.

 However it appears from the code in
 ValidatorAction.getValidationClassInstance() that I can't actually set
 these at any point in the Validator framework so that they will be
 picked up when run under struts.

 I think I'm looking in the right place in the code.

 I was hoping that there would be some method for configuring this via
 validation.xml, but apparently not.

 Am I correct?

 Thanks
 Adam

 -- 
 struts 1.1 + tomcat 5.0.16 + java 1.4.2
 Linux 2.4.20 Debian


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]






-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: UrlValidator() takes options - but how?

2004-04-01 Thread Niall Pemberton
The problem with GenericValidator is that it has a single instance of
UrlValidator in a static variable, so you can't go changing its
configuration every time a url is validated in your webapp as it wouldn't be
thread safe. In fact if you want the option to configure it on a field by
field basis then you are going to need to create a new instance of the
UrlValidator each time - or have some clever mechanism that caches a
UrlValidator for each field -its a shame the ValidatorAction doesn't do
that.

Maybe modify FieldChecks.validateUrl() to check if any options/schemes have
been set (using var) - if they have then instantiate a new UrlValidator,
otherwise use the default GenericValidator.isUrl().

The other problem, which I usually forget is the javascript - if you allow
the server side to be configured then maybe the  javascript should also take
those options into account (although the date validation only works with the
datePatternStrict option in javascript unless its changed in 1.2).

Anyway my opinion is irrelevant as its the powers that be that you have to
convince to apply any patch you submit :-)

Niall


- Original Message - 
From: Adam Hardy [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Thursday, April 01, 2004 3:24 PM
Subject: Re: UrlValidator() takes options - but how?


 Thanks for that Niall, you certainly know your stuff.

 I am thinking, if I change the UrlValidator in the source code, I could
 submit a patch to allow FieldChecks to set the var values from
 validation.xml.

 Currently, FieldChecks access UrlValidator via the GenericValidator:

 if (!GenericValidator.isBlankOrNull(value) 
  !GenericValidator.isUrl(value)) {

 Should I change this to:

   !GenericValidator.isUrl(value, allow2Slashes, noFragments,
 allowAllSchems)) {

 and edit GenericValidator accordingly, to pass the options in to
 UrlValidator.

 Is that a good idea?
 Adam


 On 04/01/2004 02:58 PM Niall Pemberton wrote:
  UrlValidator is not the class that is instantiated  by ValidatorAction
  because it doesn't know anything about Struts resources - the Struts
  FieldChecks.validateUrl() method calls commons GenericValidator which
  instantiates the UrlValidator.
 
  Rather than using the struts FieldChecks.validateUrl(), create you own
  version which instantiates the url validator and picks up var values
to
  configure it. Something like:
 
 
  field property=someUrl depends=myUrlValidator
varvar-nameslashes/var-name
  var-valuetrue/var-value
/var
varvar-namefragments/var-name
  var-valuetrue/var-value
/var
  /field
 
 public static boolean validateUrl(Object bean,
  ValidatorAction va, Field field,
  ActionMessages errors,
  HttpServletRequest request) {
 
  String value = null;
  if (isString(bean)) {
  value = (String) bean;
  } else {
  value = ValidatorUtils.getValueAsString(bean,
  field.getProperty());
  }
  int options = 0;
 
  if (true.equals(field.getVarValue(slashes)))
   options += UrlValidator.ALLOW_2_SLASHES;
 
  if (true.equals(field.getVarValue(fragments)))
   options += UrlValidator.ALLOW_2_SLASHES;
 
  UrlValidator urlValidator = new UrlValidator(options);
 
  if (!GenericValidator.isBlankOrNull(value) 
  !urlValidator.isValid(value)) {
  errors.add(field.getKey(),
Resources.getActionMessage(request,
  va, field));
  return false;
  } else {
  return true;
  }
  }
 
  - Original Message - 
  From: Adam Hardy [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Thursday, April 01, 2004 12:17 PM
  Subject: UrlValidator() takes options - but how?
 
 
 
 In UrlValidator() in the validator package, one can set various options
 upon instantiation, such as ALLOW_2_SLASHES or NO_FRAGMENTS.
 
 However it appears from the code in
 ValidatorAction.getValidationClassInstance() that I can't actually set
 these at any point in the Validator framework so that they will be
 picked up when run under struts.
 
 I think I'm looking in the right place in the code.
 
 I was hoping that there would be some method for configuring this via
 validation.xml, but apparently not.
 
 Am I correct?
 
 Thanks
 Adam
 
 -- 
 struts 1.1 + tomcat 5.0.16 + java 1.4.2
 Linux 2.4.20 Debian
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 
 
 
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 


 -- 
 struts 1.2 + tomcat 5.0.19 + java 1.4.2
 Linux 2.4.20 Debian

Re: UrlValidator() takes options - but how?

2004-04-01 Thread Niall Pemberton
Adam,

I forwarded one of my replies by mistake to the developer list, but one of
the committers picked up on it so I thought I'd let you know if you'd like
to get into the dicussion over there

Niall


- Original Message - 
From: Adam Hardy [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Thursday, April 01, 2004 3:24 PM
Subject: Re: UrlValidator() takes options - but how?


 Thanks for that Niall, you certainly know your stuff.

 I am thinking, if I change the UrlValidator in the source code, I could
 submit a patch to allow FieldChecks to set the var values from
 validation.xml.

 Currently, FieldChecks access UrlValidator via the GenericValidator:

 if (!GenericValidator.isBlankOrNull(value) 
  !GenericValidator.isUrl(value)) {

 Should I change this to:

   !GenericValidator.isUrl(value, allow2Slashes, noFragments,
 allowAllSchems)) {

 and edit GenericValidator accordingly, to pass the options in to
 UrlValidator.

 Is that a good idea?
 Adam


 On 04/01/2004 02:58 PM Niall Pemberton wrote:
  UrlValidator is not the class that is instantiated  by ValidatorAction
  because it doesn't know anything about Struts resources - the Struts
  FieldChecks.validateUrl() method calls commons GenericValidator which
  instantiates the UrlValidator.
 
  Rather than using the struts FieldChecks.validateUrl(), create you own
  version which instantiates the url validator and picks up var values
to
  configure it. Something like:
 
 
  field property=someUrl depends=myUrlValidator
varvar-nameslashes/var-name
  var-valuetrue/var-value
/var
varvar-namefragments/var-name
  var-valuetrue/var-value
/var
  /field
 
 public static boolean validateUrl(Object bean,
  ValidatorAction va, Field field,
  ActionMessages errors,
  HttpServletRequest request) {
 
  String value = null;
  if (isString(bean)) {
  value = (String) bean;
  } else {
  value = ValidatorUtils.getValueAsString(bean,
  field.getProperty());
  }
  int options = 0;
 
  if (true.equals(field.getVarValue(slashes)))
   options += UrlValidator.ALLOW_2_SLASHES;
 
  if (true.equals(field.getVarValue(fragments)))
   options += UrlValidator.ALLOW_2_SLASHES;
 
  UrlValidator urlValidator = new UrlValidator(options);
 
  if (!GenericValidator.isBlankOrNull(value) 
  !urlValidator.isValid(value)) {
  errors.add(field.getKey(),
Resources.getActionMessage(request,
  va, field));
  return false;
  } else {
  return true;
  }
  }
 
  - Original Message - 
  From: Adam Hardy [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Thursday, April 01, 2004 12:17 PM
  Subject: UrlValidator() takes options - but how?
 
 
 
 In UrlValidator() in the validator package, one can set various options
 upon instantiation, such as ALLOW_2_SLASHES or NO_FRAGMENTS.
 
 However it appears from the code in
 ValidatorAction.getValidationClassInstance() that I can't actually set
 these at any point in the Validator framework so that they will be
 picked up when run under struts.
 
 I think I'm looking in the right place in the code.
 
 I was hoping that there would be some method for configuring this via
 validation.xml, but apparently not.
 
 Am I correct?
 
 Thanks
 Adam
 
 -- 
 struts 1.1 + tomcat 5.0.16 + java 1.4.2
 Linux 2.4.20 Debian
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 
 
 
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 


 -- 
 struts 1.2 + tomcat 5.0.19 + java 1.4.2
 Linux 2.4.20 Debian


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]






-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]