mailgun / mailgun-go

Go library for sending mail with the Mailgun API.
BSD 3-Clause "New" or "Revised" License
695 stars 143 forks source link

Incorrect use of strconv.Unquote in messages.go #324

Open IvanWillsBI opened 3 months ago

IvanWillsBI commented 3 months ago
func (m *Message) AddVariable(variable string, value interface{}) error {
    if m.variables == nil {
        m.variables = make(map[string]string)
    }

    j, err := json.Marshal(value)
    if err != nil {
        return err
    }

    encoded := string(j)
    v, err := strconv.Unquote(encoded)
    if err != nil {
        v = encoded
    }

    m.variables[variable] = v
    return nil
}

Doesn't work for boolean values or numbers (non string values, as they don't appear as ""foo"")

Therefore, in my mailgun template which uses {{#if }} handlebars, I cannot check the boolean value, as it is sent as a string

vtopc commented 1 week ago

Hi, @IvanWillsBI.

There is a test for boolean: https://github.com/mailgun/mailgun-go/blob/88d455cf93e9834b53564a654522ac1995120469/messages_test.go#L389 is it incorrect? I can't get why it should be ""foo"".


_NOTES for myself:

112

https://documentation.mailgun.com/docs/mailgun/user-manual/sending-messages/#handlebars https://handlebarsjs.com/guide/builtin-helpers.html#if_