 |
Castle Project Support forum
|
| View previous topic :: View next topic |
| Author |
Message |
tomasr
Joined: 16 Aug 2007 Posts: 5
|
Posted: Thu Aug 16, 2007 1:50 am Post subject: ValidateRegEx and string escaping (client side) |
|
|
I'm running into a bit of a snag with the client side validation facilities in Monorail using ValidateRegEx. It seems that when it generates the JS for the client-side validation, it fails to correctly escape "\" characters, thus leading to an invalid JS regex pattern.
Here's an example; let's say I have this pattern:
[ValidateRegExp(@"\+\d{1,3} \(\d+\) \d+")]
This seems to get translated into the following piece of JS:
{ pattern : new RegExp("\+\d{1,3} \(\d+\) \d+") }
Since this is a string and not a regex pattern (i.e /.../). the single \ gets ignored and this the expression is interpreted as:
+d{1,3} (d+) d+
which is obviously not what I wanted... The right expression is, of course, perfectly valid JS, so it should really have been converted as:
new RegExp("\\+\\d{1,3} \\(\\d+\\) \\d+")
I'm using a fairly recent build, and didn't see anything relevant in JIRA, either. Any ideas? |
|
| Back to top |
|
 |
hammett Castle Team

Joined: 15 Apr 2006 Posts: 1739 Location: SP, Brasil
|
Posted: Thu Aug 16, 2007 2:38 am Post subject: |
|
|
When you say fairly recent you mean a last week's? If the latest build doesnt work, can you please fill a jira issue with some code that reproduces it? I shall check it shortly. Thanks _________________ Cheers,
hammett
http://hammett.castleproject.org/ |
|
| Back to top |
|
 |
tomasr
Joined: 16 Aug 2007 Posts: 5
|
Posted: Thu Aug 16, 2007 2:52 am Post subject: |
|
|
Hammett,
It's fairly recent. I think I downloaded one of yesterday's builds. I'll gladly jira it; but just to make sure, do you want it registered under the validator component or under monorail? |
|
| Back to top |
|
 |
tomasr
Joined: 16 Aug 2007 Posts: 5
|
Posted: Sat Aug 18, 2007 3:06 pm Post subject: |
|
|
OK, I went ahead and got the source from SVN and looked at it myself. Indeed, the problem is as I described. For the Prototypes validator, it can be fixed by changing line 212 of PrototypeWebValidator.cs to:
config.AddCustomRule(rule, violationMessage, "pattern : new RegExp(\"" + regExp.Replace(@"\", @"\\") + "\")");
I don't know about the ZebdaWebValidator as I haven't used it. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|