Skip to content

Commit

Permalink
Add flag to disable unicode escaping in Dump
Browse files Browse the repository at this point in the history
  • Loading branch information
G33kDude committed Jan 31, 2022
1 parent e0e20f1 commit 9b01c6e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
16 changes: 16 additions & 0 deletions Src/JSON.ahk
Expand Up @@ -19,6 +19,22 @@ class JSON
}
}

EscapeUnicode[]
{
get
{
this._init()
return NumGet(this.lib.bEscapeUnicode, "Int")
}

set
{
this._init()
NumPut(value, this.lib.bEscapeUnicode, "Int")
return value
}
}

_init()
{
if (this.lib)
Expand Down
7 changes: 5 additions & 2 deletions Src/dumps.c
Expand Up @@ -239,8 +239,11 @@ int write_escaped(LPTSTR pt, LPTSTR *ppszString, DWORD *pcchString)
write('\\');
write('t');
}
else if (*pt < ' ' || *pt > '~') // outside printable ascii
{
else if (
bEscapeUnicode
? ((unsigned short)*pt < ' ' ||(unsigned short)*pt > '~') // Outside printable ascii
: ((unsigned short)*pt < ' ' || ((unsigned short)*pt > '~' && (unsigned short)*pt < 0xA1)) // Outside printable ascii, allowing Unicode passthrough
) {
write('\\');
write('u');
write_hex_uint16(*pt, ppszString, pcchString);
Expand Down
3 changes: 3 additions & 0 deletions Src/shared.h
Expand Up @@ -25,4 +25,7 @@ MCL_EXPORT_GLOBAL(fnGetObj);
static bool bBoolsAsInts = true;
MCL_EXPORT_GLOBAL(bBoolsAsInts);

static bool bEscapeUnicode = true;
MCL_EXPORT_GLOBAL(bEscapeUnicode);

#endif
8 changes: 8 additions & 0 deletions Tests/DumpsTestSuite.ahk
Expand Up @@ -112,6 +112,14 @@ class DumpsTestSuite
Yunit.assert(produced == expected, Format(this.message, expected, produced))
}

Test_Escape_Unicode()
{
JSON.EscapeUnicode := False
expected = ["📎🐟💝🐤🔼🏡👓 🍩🌅🌳🐔🏩🍎 📵🍭🌖🔠🍚"]
produced := JSON.Dump(["📎🐟💝🐤🔼🏡👓 🍩🌅🌳🐔🏩🍎 📵🍭🌖🔠🍚"])
Yunit.assert(produced == expected, Format(this.message, expected, produced))
}

Test_Big_Numbers()
{
if (A_PtrSize == 4)
Expand Down

0 comments on commit 9b01c6e

Please sign in to comment.