Home

Castle Stronghold

Castle Project Forum Index Castle Project
Support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ValidateRegEx and string escaping (client side)

 
Post new topic   Reply to topic    Castle Project Forum Index -> MR Usage
View previous topic :: View next topic  
Author Message
tomasr



Joined: 16 Aug 2007
Posts: 5

PostPosted: Thu Aug 16, 2007 1:50 am    Post subject: ValidateRegEx and string escaping (client side) Reply with quote

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
View user's profile Send private message
hammett
Castle Team


Joined: 15 Apr 2006
Posts: 1739
Location: SP, Brasil

PostPosted: Thu Aug 16, 2007 2:38 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
tomasr



Joined: 16 Aug 2007
Posts: 5

PostPosted: Thu Aug 16, 2007 2:52 am    Post subject: Reply with quote

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
View user's profile Send private message
tomasr



Joined: 16 Aug 2007
Posts: 5

PostPosted: Sat Aug 18, 2007 3:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Castle Project Forum Index -> MR Usage All times are GMT
Page 1 of 1

 
Jump to:  
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