This project is read-only.

regular expression escaped character bug?

Jan 28, 2015 at 8:15 PM
i am using the nuget package 1.0.7 in a project.

When using a regular expression with escaped characters, such as \S and (, the backslashes are escaped in the unobtrusive span tag.

For example, the following attribute ( will output the following span.
<Required(ErrorMessage:="10-digit phone number is required."), RegularExpression("\(?[2-9][0-9]{2}\)?[- ]?[0-9]{3}[- ]?[0-9]{4}", ErrorMessage:="10-digit phone number is required.")> _
<dav:DataAnnotationsValidator ID="davPhone" runat="server" 
                                        ObjectProperty="Phone" Display="None" />
<span style="color:Red;display:none;" data-val="true" id="ContactForm_davPhone" data-val-display="None" data-val-controltovalidate="ContactForm_Phone" data-val-supresserrormessagetext="false" data-val-errormessages="10-digit phone number is required.;;10-digit phone number is required." data-val-validatorfunctions="RequiredFieldValidatorEvaluateIsValid;;RegularExpressionValidatorEvaluateIsValid" data-val-validationexpression="\\(?[2-9][0-9]{2}\\)?[- ]?[0-9]{3}[- ]?[0-9]{4}" data-val-initialvalue="" data-val-evaluationfunction="DAValidation.DataAnnotationsValidatorIsValid"></span>
I see in RegularExpressionClientValidationRule.cs the last line is what escapes the backslashes.
Parameters["validationexpression"] = HttpUtility.JavaScriptStringEncode(pattern);
Any ideas?
Jan 31, 2015 at 8:49 PM
Yes, looks like this encoding call is redundant. I'll do some tests and will make sure to release a fix soon.

Feb 11, 2015 at 11:51 AM
Fix for this issue was shipped with DAValication 1.0.8 release. Feel free to update from nuget or download from codeplex.
Feb 26, 2015 at 3:42 AM
Looks good