-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Decode at-mark and backslash ( #1307 ) #1588
Conversation
This is a nice pull request, but it doesn't account for
I haven't tested your PR locally yet, I'm just assuming Note that, per my issuecomment, only backslash, at, and percent are likely to be affected. |
OK, I will decode percent too. Thanks @joker314 |
In Scratch 2.0, the algorithm for escaping the data is not the mirror image of the algorithm for unescaping that data. This pull request, however, takes the mirror image of the escape function. This is absolutely fine; and the only time this will not work is if there's 'hacked' JSON. Somebody may modify their string like so: - ask user how they are doing
+ \a\s\k\ \u\s\e\r\ \h\o\w\ \t\h\e\y\ \a\r\e\ \d\o\i\n\g Upon performing such a modification, their project would behave identically. There's no reason to make such a change as a JSON hacker (and so there's no reason to worry about it in this PR, maybe), however, if such a modification has been made, this pull request would leave the backslashes in. I'd say that this is absolutely fine and we shouldn't worry about it. Regarding the chaining of .replace(/\\([%@\\])/g, '$1') might be shorter. I'm not sure if this is more readable? I also don't know how this may impact efficiency -- it's a style choice that you may wish to consider. This could be modified to resolve the above issue about hacked JSONs like so: .replace(/\\(.)/g, '$1') Though, as stated earlier, the hacked JSON issue seems like a non-issue. |
I added percent decoding, but it uses full-width percent to avoid scratchfoundation/scratch-blocks#1368 |
Hmm. Maybe I was wrong about us needing to decode EDIT: Scratch 2.0 will always encode percent symbols with a preceding backslash. Hence, Scratch 3.0 is assigning some percent signs special meanings -- but others not. Likely, if there's a character after the percent sign, it'll become a special token. EDIT: I can only seem to get the first percent sign to be treated as something that can be escaped. |
Okay, some things to note:
|
@joker314 It's already help-wanted, scratchfoundation/scratch-blocks#1368 |
@apple502j When you made the change to the full-width percent sign, did you actually manage to get a working example of a 2.0 project that would cause scratchfoundation/scratch-blocks#1368 to happen? |
@joker314 Oops, 1368 was not related at all. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably okay to remove the replacement to the full-width percent sign, then?
@apple502j, Thanks for making this pull request! We are a little backed up on code reviews at the moment, but we'll take a look at these changes soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@apple502j, Thank you for the pull request! I have left a comment in the code changes.
@@ -1061,7 +1061,8 @@ const parseBlock = function (sb2block, addBroadcastMsg, getVariableId, extension | |||
children: [], | |||
mutation: { | |||
tagName: 'mutation', | |||
proccode: procData[0], // e.g., "abc %n %b %s" | |||
proccode: procData[0].replace(/\\%/g, '%').replace(/\\(.)/g, '$1'), |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
@@ -1061,7 +1061,8 @@ const parseBlock = function (sb2block, addBroadcastMsg, getVariableId, extension | |||
children: [], | |||
mutation: { | |||
tagName: 'mutation', | |||
proccode: procData[0], // e.g., "abc %n %b %s" | |||
proccode: procData[0].replace(/\\%/g, '%').replace(/\\(.)/g, '$1'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this is a fullwidth percent sign-- "replace this character with another very similar looking character" strikes me as somewhat janky
Hmm, maybe I should make better one |
Resolves
Fixes #1307
Proposed Changes
Decode
\\@
and\\\\
using regex and replace. The issue didn't contain the backslash one, but I also found that, so it contains fix for that.Reason for Changes
Not to change custom block name.
Test Coverage
https://scratch.mit.edu/projects/246543955/
This project has 2 custom blocks named
@atmark@
and\backslash\
Tested using above with Windows 7, Firefox 62 and Chrome 68