Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegExp for json form rules fails #87

Closed
redhead opened this issue Aug 11, 2010 · 7 comments
Closed

RegExp for json form rules fails #87

redhead opened this issue Aug 11, 2010 · 7 comments

Comments

@redhead
Copy link
Contributor

@redhead redhead commented Aug 11, 2010

Regular expression for creating optimized JSON form rules (for data-rules attr) fails when there are escaped unicode character sequences (it should take into account only escaped quote character).


// this one fails (FormControl.php; line 387):
$rules = preg_replace('#"([^\\\\"\']*)"#i', "'$1'", $rules);

Is there any reason to replace double quotes for single quotes, anyway??

@redhead

This comment has been minimized.

Copy link
Contributor Author

@redhead redhead commented Aug 11, 2010

It fails in the way that it results in: msg:"nejaky zprava'
(starting and ending qoute doesn't match each other, so it fails in javascript)

@jsmitka

This comment has been minimized.

Copy link
Contributor

@jsmitka jsmitka commented Aug 11, 2010

Should by fixed in my fork of Nette, please give it a try. ;-) Pull request pending.

The reason for replacing the double quotes by an apostrophe is simple: to save space. " has to be encoded as an entity in the HTML ("), while ' can stay untouched.

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Aug 11, 2010

Is there any reason to replace double quotes for single quotes, anyway??

Only visual:

  • data-rules="{op:":filled",msg:"Enter your name"}"
    versus
  • data-rules="{op:':filled',msg:'Enter your name'}"
@redhead

This comment has been minimized.

Copy link
Contributor Author

@redhead redhead commented Aug 11, 2010

Oh, right. I forgot that. :)

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Aug 11, 2010

FormControl: fixed data-rules attribute optimization [Closed by 478f2da78181c416373cc9651a8efda139dc2dec]

@jsmitka

This comment has been minimized.

Copy link
Contributor

@jsmitka jsmitka commented Aug 11, 2010

It's still buggy - try using a quote not followed by an comma in the rule's message. It will result in something like this:

{op:':filled',msg:"Test of \'quote'}

Therefore, it's necessary to check the character before the first quote. So you can

  1. assure that the previous character is an colon, which is safer, in my opinion. In addition, checking for comma in string is not necessary: Sorry, it is necessary to check for the comma in the string, otherwise it will match the wrong string again. I've fixed the regexp.

    #(?<=:)"([^\\\\"\',]*)"#i
    
  2. assure that the previous character is not a backslash:

    #(?<!\\\\)"([^\\\\"\',]*)"#i
    
@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Aug 11, 2010

Now hopefully fixed ;)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.