forked from nyaruka/gocommon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from nyaruka/main
Update from base repo
- Loading branch information
Showing
10 changed files
with
172 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,11 @@ jobs: | |
strategy: | ||
matrix: | ||
go-version: [1.19.x] | ||
pg-version: ["12", "13"] | ||
pg-version: ["13", "14"] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v1 | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install PostgreSQL | ||
uses: harmon758/postgresql-action@v1 | ||
|
@@ -26,10 +26,10 @@ jobs: | |
- name: Install Redis | ||
uses: zhulik/[email protected] | ||
with: | ||
redis version: "5" | ||
redis version: "6.2" | ||
|
||
- name: Install Go | ||
uses: actions/setup-go@v1 | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dbutil | ||
|
||
import "strings" | ||
|
||
// ToValidUTF8 replaces invalid UTF-8 sequences with � characters and also strips NULL characters, which whilst being | ||
// valid UTF-8, can't be saved to PostgreSQL. | ||
func ToValidUTF8(s string) string { | ||
return strings.ReplaceAll(strings.ToValidUTF8(s, `�`), "\x00", "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package dbutil_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/nyaruka/gocommon/dbutil" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestToValidUTF8(t *testing.T) { | ||
tcs := []struct { | ||
input string | ||
expected string | ||
}{ | ||
{"", ""}, | ||
{"hello\nworld", "hello\nworld"}, | ||
{"hello\xc3\x28world", "hello�(world"}, // invalid 2 octet sequence | ||
{"hello\xa0\xa1world", "hello�world"}, // invalid sequence identifier | ||
{"hello\xe2\x28\xa1world", "hello�(�world"}, // invalid 3 octet sequence | ||
{"\u0000hello world\x00", "hello world"}, // null character | ||
} | ||
|
||
for _, tc := range tcs { | ||
actual := dbutil.ToValidUTF8(tc.input) | ||
assert.Equal(t, tc.expected, actual) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.