-
Notifications
You must be signed in to change notification settings - Fork 122
Fix SGF parsing regular expressions, fix #36 #37
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
base: master
Are you sure you want to change the base?
Conversation
- SGF parsing can currently be broken by an escaped backslash preceding an ending square bracket: '\\]'
- SGF parsing can currently be broken by an escaped backslash preceding an ending square bracket: '\\]'
|
Thanks for solving this issue (I wasn't at home). I will check it and merge soon. |
|
No problem! It's a pretty understandable oversight since it's such an edge case to have an intended (and escaped) backslash right before a closing bracket, but it managed to break the game to an impressive degree. 😄 |
|
I have an improvement on @neagle code. It is still to be tested but here it is: If I understand it is done to detect the between square bracket elements expanded with explanation pcre with /x modifier I tested both regexp with regex101 online tool ( https://regex101.com/r/bF0jQ5/4 for compact and js one and https://regex101.com/r/bF0jQ5/2 for pcre and explained one ) It looks that both work By the way looks like on some cases, your version eat too much your version eat both comment and that between: https://regex101.com/r/bF0jQ5/5 while mine take just the first https://regex101.com/r/fB2hF2/1 (originally in in neagle/gokibitz#92 (comment) which is said by @neagle as a clarity improvement and fix bug improvement) |
|
@xcombelle code looks pretty and works. However I would suggest a little improvement. According to SGF specification you can escape new line characters. Therefore I would use this reg exp: /\[([^\\\]]|\\(.|\n|\r))*\]/gand then I would remove these line breaks. Please check it and I will update master branch. |
|
You are full right I actually missed that . don't match carriage return in javascript (good catch) |
|
Does this change work for all of these test cases?
|
|
@yewang yes it should works for these uses cases you can test it on https://regex101.com/r/bF0jQ5/6 (I tested the four) |
This was all caused by an emoticon:
:/SGF parsing can currently be broken by an escaped backslash preceding an ending square bracket: ']'
This updates the regular expressions used to parse sequences and properties to account for the possibility that a preceding backslash has been, itself, escaped.