Skip to content

Commit

Permalink
fix: unicode error
Browse files Browse the repository at this point in the history
  • Loading branch information
saimanoj committed Aug 4, 2023
1 parent f26c08c commit ddbf590
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 26 deletions.
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ require (
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
Expand Down
9 changes: 0 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
Expand Down Expand Up @@ -166,8 +165,6 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
Expand All @@ -188,11 +185,6 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pierrec/lz4/v4 v4.1.17 h1:kV4Ip+/hUBC+8T6+2EgburRtkE9ef4nbY3f4dFhGjMc=
github.com/pierrec/lz4/v4 v4.1.17/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
Expand All @@ -218,7 +210,6 @@ github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUq
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
21 changes: 7 additions & 14 deletions internal/ticketing/ticketing.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"io"
"net/http"
"net/url"
"regexp"
"strconv"
"strings"
"time"

jsoniter "github.com/json-iterator/go"
"github.com/poozlehq/cq-source-ticketing/internal/httperror"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -200,7 +200,6 @@ func (s *Client) GetCollection(ctx context.Context, pageUrl string, params url.V

func (s *Client) GetTicket(ctx context.Context, pageUrl string, params url.Values) (*TicketResponse, url.Values, error) {
var ret TicketResponse
var json = jsoniter.ConfigCompatibleWithStandardLibrary

log.Debug().Str("cursor", pageUrl).Msg("This is the pageurl for GetTicket")

Expand All @@ -212,12 +211,9 @@ func (s *Client) GetTicket(ctx context.Context, pageUrl string, params url.Value

// err = json.NewDecoder(resp.Body).Decode(&ret)
bodyBytes, _ := io.ReadAll(resp.Body)
// re := regexp.MustCompile(`\\u[0-9a-fA-F]{4}`)
// re := regexp.MustCompile(`\\u([0-9a-fA-F]{4})`)
// cleanedBody := re.ReplaceAllString(string(bodyBytes), "")
// err = json.NewDecoder(strings.NewReader(cleanedBody)).Decode(&ret)

err = json.Unmarshal(bodyBytes, &ret)
re := regexp.MustCompile(`\\u0000`)
cleanedBody := re.ReplaceAllString(string(bodyBytes), "")
err = json.NewDecoder(strings.NewReader(cleanedBody)).Decode(&ret)

if err != nil {
log.Info().Str("pageUrl", string(pageUrl)).Str("params", fmt.Sprintf("%v", params)).Msg("This is the body")
Expand All @@ -232,7 +228,6 @@ func (s *Client) GetTicket(ctx context.Context, pageUrl string, params url.Value

func (s *Client) GetComment(ctx context.Context, pageUrl string, params url.Values) (*CommentResponse, url.Values, error) {
var ret CommentResponse
var json = jsoniter.ConfigCompatibleWithStandardLibrary

log.Debug().Str("cursor", pageUrl).Msg("This is the pageurl for GetComment")

Expand All @@ -244,12 +239,10 @@ func (s *Client) GetComment(ctx context.Context, pageUrl string, params url.Valu

// err = json.NewDecoder(resp.Body).Decode(&ret)
bodyBytes, _ := io.ReadAll(resp.Body)
// re := regexp.MustCompile(`\\u[0-9a-fA-F]{4}`)
// re := regexp.MustCompile(`\\u([0-9a-fA-F]{4})`)
// cleanedBody := re.ReplaceAllString(string(bodyBytes), "")
// err = json.NewDecoder(strings.NewReader(cleanedBody)).Decode(&ret)
re := regexp.MustCompile(`\\u0000`)
cleanedBody := re.ReplaceAllString(string(bodyBytes), "")
err = json.NewDecoder(strings.NewReader(cleanedBody)).Decode(&ret)

err = json.Unmarshal(bodyBytes, &ret)
if err != nil {
log.Error().Err(err).Msg("Error decoding body response")
return nil, nil, err
Expand Down

0 comments on commit ddbf590

Please sign in to comment.