Skip to content

Commit

Permalink
chore: better name for hex const
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Nov 7, 2021
1 parent 0b33cb0 commit 185d9c3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions enc_str.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ var safeSet = [utf8.RuneSelf]bool{
'\u007f': true,
}

const hex = "0123456789abcdef"
const hexChars = "0123456789abcdef"

// StrEscape encodes string with html special characters escaping.
func (e *Encoder) StrEscape(v string) {
Expand Down Expand Up @@ -267,7 +267,7 @@ func (e *Encoder) strEscape(i int, v string, valLen int) {
// user-controlled strings are rendered into JSON
// and served to some browsers.
e.Raw(`\u00`)
e.twoBytes(hex[b>>4], hex[b&0xF])
e.twoBytes(hexChars[b>>4], hexChars[b&0xF])
}
i++
start = i
Expand Down Expand Up @@ -295,7 +295,7 @@ func (e *Encoder) strEscape(i int, v string, valLen int) {
e.Raw(v[start:i])
}
e.Raw(`\u202`)
e.byte(hex[c&0xF])
e.byte(hexChars[c&0xF])
i += size
start = i
continue
Expand Down Expand Up @@ -361,7 +361,7 @@ func (e *Encoder) strSlow(i int, v string, length int) {
// user-controlled strings are rendered into JSON
// and served to some browsers.
e.Raw(`\u00`)
e.twoBytes(hex[b>>4], hex[b&0xF])
e.twoBytes(hexChars[b>>4], hexChars[b&0xF])
}
i++
start = i
Expand Down
4 changes: 2 additions & 2 deletions string_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package jx

import (
hexEnc "encoding/hex"
"encoding/hex"
"encoding/json"
"testing"

Expand Down Expand Up @@ -106,7 +106,7 @@ func TestEncoder_Str(t *testing.T) {
i := DecodeBytes(s.Bytes())
got, err := i.Str()
require.NoError(t, err)
require.Equal(t, tt.Input, got, "%s\n%s", s, hexEnc.Dump(s.Bytes()))
require.Equal(t, tt.Input, got, "%s\n%s", s, hex.Dump(s.Bytes()))
})
}
}

0 comments on commit 185d9c3

Please sign in to comment.