Skip to content

Commit

Permalink
Fixed handling of UTF-8 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaskin committed Apr 26, 2018
1 parent e48dabe commit afa07f9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
27 changes: 14 additions & 13 deletions patch32lsb/patch32lsb.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"errors"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -191,7 +192,7 @@ func unescape(str string) (string, error) {
}
str = str[1 : len(str)-1]

nstr := ""
var buf bytes.Buffer
for {
if len(str) == 0 {
break
Expand All @@ -200,49 +201,49 @@ func unescape(str string) (string, error) {
case '\\':
switch str[1] {
case 'n':
nstr += "\n"
buf.Write([]byte("\n"))
str = str[2:]
case 'r':
nstr += "\r"
buf.Write([]byte("\r"))
str = str[2:]
case 't':
nstr += "\t"
buf.Write([]byte("\t"))
str = str[2:]
case 'v':
nstr += "\v"
buf.Write([]byte("\v"))
str = str[2:]
case '"':
nstr += "\""
buf.Write([]byte("\""))
str = str[2:]
case '\'':
nstr += "'"
buf.Write([]byte("'"))
str = str[2:]
case '`':
nstr += "`"
buf.Write([]byte("`"))
str = str[2:]
case '0':
nstr += "\x00"
buf.Write([]byte("\x00"))
str = str[2:]
case '\\':
nstr += "\\"
buf.Write([]byte("\\"))
str = str[2:]
case 'x':
var b []byte
_, err := fmt.Sscanf(str[2:4], "%x", &b)
if err != nil {
return "", err
}
nstr += string(b)
buf.Write(b)
str = str[4:]
default:
return "", errors.New("unknown escape " + string(str[1]))
}
default:
nstr += string(str[0])
buf.Write([]byte{str[0]})
str = str[1:]
}
}
return nstr, nil
return string(buf.Bytes()), nil
}

func unescapeFirst(str string) (string, string, error) {
Expand Down
1 change: 1 addition & 0 deletions patch32lsb/patch32lsb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func TestUnescape(t *testing.T) {
{`test\0\xcc`, "test\x00\xcc"},
{`test\0\n\t\v\r\xcc`, "test\x00\n\t\v\r\xcc"},
{`test\0\n\t\v\r\xcc\"\'\` + "`", "test\x00\n\t\v\r\xcc\"'`"},
{`ÉÀÇ`, "ÉÀÇ"},
} {
u, err := unescape("`" + c[0] + "`")
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion patchlib/testdata/libnickel.so.1.0.0.patch.all
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ replace_int = 9F6252, 3, 5

<Patch>
patch_name = `Keyboard template (Mini/Touch/Glo/Aura)`
patch_enable = `yes`
patch_enable = `no`
# patch_group = `Keyboard alternatives`
#
## Replaces keys on the Extended Latin keypad with custom alternatives.
Expand Down

0 comments on commit afa07f9

Please # to comment.