Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Handling GM Notes encoding

1458031892
Lucian
Pro
API Scripter
Hi All, I'm updating an old script and trying to get the code as clean as possible. One of the things I want to change is that it uses the deprecate "unescape" function to remove the escape sequences from text that has been pulled from GM Notes etc. My first thought was simply to switch this out or decodeURI, but then it occurred to me that I don't actually know what the escaping scheme really is. The  wiki suggests a function that just handles % encoded characters, but I have no idea whether that is accurate/up to date, or if it's just "what worked for someone". Does anyone have any authoritative information on what the escaping scheme is, and whether it would be safe to just call decodeURI?
1458040494
The Aaron
Pro
API Scripter
I'm pretty sure I wrote that. I did quite a bit of digging about but I wouldn't necessarily consider it authoritative. In fact, I'm pretty sure there's a bit more to it. 
1458040763
Lucian
Pro
API Scripter
The Aaron said: I'm pretty sure I wrote that. I did quite a bit of digging about but I wouldn't necessarily consider it authoritative. In fact, I'm pretty sure there's a bit more to it.  Ok, well that's good to know. Anyone from Roll20 care to comment? I guess it should be pretty easy for you guys to say: "this is the function/mechanism we use to encode the contents of the GM Notes" and then we can work back from there....
1458050764
Lithl
Pro
Sheet Author
API Scripter
I recommend decodeURIComponent over decodeURI. decodeURI only exists as a compliment to encodeURI, which pretty much only exists for a few very corner cases with broken URI strings. IIRC, decodeURI has some functionality problems, too. On the other hand, decodeURIComponent and encodeURIComponent are used frequently for query strings without error. Considering the text of your GM Notes field isn't  a URI, too, the *Component function is more semantically correct.
1458051452
The Aaron
Pro
API Scripter
One other thing to be aware of, you can end up with HTML entities like > where you had >.  It won't be visible in the display, but will be present in the data.  For one script I'm working on, that caused some problems...
1458215611
Lucian
Pro
API Scripter
How about  _.unescape(decodeURIComponent(text)) ? I don't think it should double unescape...