Skip to content

Commit

Permalink
Fixed a bug that caused line feeds to not always be escaped. Fixed a …
Browse files Browse the repository at this point in the history
…bug that caused '\' and '/' escaping to be the wrong way round
  • Loading branch information
raphaelcohn committed Jan 8, 2015
1 parent b928d90 commit 41f753c
Showing 1 changed file with 49 additions and 51 deletions.
100 changes: 49 additions & 51 deletions jsonwriter.functions
Original file line number Diff line number Diff line change
Expand Up @@ -222,75 +222,73 @@ jsonwriter_null()
printf 'null'
}

# There are actually flaws in the escaping of UTF-8 encoding in this routine
# There might be flaws in the escaping of UTF-8 encoding in this routine
core_dependency_requires '*' awk
jsonwriter_string()
{
printf '"'
printf '%s' "$1" | awk -v ORS='' -v FS='' -v OFS='' '
printf '%s' "$1" | awk '
BEGIN {
srand()
FS=""
RS="n/o/m/a/t/c/h" rand()
ORS=""

for (n = 0; n < 256; n++)
{
ord[sprintf("%c", n)] = n
}
}

{
if (NF == 0)
{
printf "\\n"
}
else
for (i = 1; i <= NF; i++)
{
for (i = 1; i <= NF; i++)
x=ord[$i]
if (x < 32)
{
x=ord[$i]
if (x < 32)
if (x == 8)
{
if (x == 8)
{
print "\\b"
}
else if (x == 10)
{
print "\\n"
}
else if (x == 12)
{
print "\\f"
}
else if (x == 13)
{
print "\\r"
}
else if (x == 9)
{
print "\\t"
}
else
{
print "\\u"
printf("%04x", x)
}
print "\\b"
}
else if (x == 10)
{
print "\\n"
}
else if (x == 12)
{
print "\\f"
}
else if (x == 13)
{
print "\\r"
}
else if (x == 9)
{
print "\\t"
}
else
{
if (x == 34)
{
print "\\" "\""
}
else if (x == 47)
{
print "\\/"
}
else if (x == 92)
{
print "\\\\"
}
else
{
print $i
}
print "\\u"
printf("%04x", x)
}
}
else
{
if (x == 34)
{
print "\\" "\""
}
else if (x == 47)
{
print "\\/"
}
else if (x == 92)
{
print "\\\\"
}
else
{
print $i
}
}
}
Expand Down

0 comments on commit 41f753c

Please sign in to comment.