diff --git a/go.mod b/go.mod index 591e298..85e803b 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,6 @@ module github.com/disgoorg/snowflake/v2 go 1.18 + +// Broken AllowUnquoted logic +retract v2.0.2 diff --git a/snowflake.go b/snowflake.go index 0eef035..c0f788e 100644 --- a/snowflake.go +++ b/snowflake.go @@ -78,9 +78,13 @@ func (id *ID) UnmarshalJSON(data []byte) error { return nil } - snowflake, err := strconv.Unquote(string(data)) - if err != nil && !AllowUnquoted { - return fmt.Errorf("failed to unquote snowflake: %w", err) + s := string(data) + snowflake, err := strconv.Unquote(s) + if err != nil { + if !AllowUnquoted { + return fmt.Errorf("failed to unquote snowflake: %w", err) + } + snowflake = s } i, err := strconv.ParseUint(snowflake, 10, 64) diff --git a/snowflake_test.go b/snowflake_test.go index 9674448..3f6608c 100644 --- a/snowflake_test.go +++ b/snowflake_test.go @@ -51,15 +51,23 @@ func TestID_UnmarshalJSON(t *testing.T) { err: nil, }, { - name: "unquoted 1", + name: "unquoted 1 no allowUnquoted", data: []byte("1"), expected: 0, - allowUnquoted: true, + allowUnquoted: false, err: strconv.ErrSyntax, }, + { + name: "unquoted 1 allowUnquoted", + data: []byte("1"), + expected: 1, + allowUnquoted: true, + err: nil, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + AllowUnquoted = tt.allowUnquoted var id ID err := json.Unmarshal(tt.data, &id)