From 2ec0e6b0112c6d8cac017163d568a6a043053016 Mon Sep 17 00:00:00 2001 From: Tadeo Kondrak Date: Sat, 13 Nov 2021 16:18:52 -0700 Subject: [PATCH] discord: Use json.Unmarshal instead for CommandInteractionOption (#292) This ensures valid JSON strings are processed using the JSON rules, not the Go rules. --- discord/interaction.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/discord/interaction.go b/discord/interaction.go index 14947d0..0417e4f 100644 --- a/discord/interaction.go +++ b/discord/interaction.go @@ -1,8 +1,6 @@ package discord import ( - "strconv" - "github.com/diamondburned/arikawa/v3/utils/json" "github.com/pkg/errors" ) @@ -285,14 +283,11 @@ type CommandInteractionOption struct { // String will return the value if the option's value is a valid string. // Otherwise, it will return the raw JSON value of the other type. func (o CommandInteractionOption) String() string { - val := string(o.Value) - - s, err := strconv.Unquote(val) - if err != nil { - return val + var value string + if err := json.Unmarshal(o.Value, &value); err != nil { + return string(o.Value) } - - return s + return value } // IntValue reads the option's value as an int.