Fixes issue with unescaped character %

Fixes #113
This commit is contained in:
Mickael Remond 2019-09-27 16:30:12 +02:00 committed by Mickaël Rémond
parent 2cdda48467
commit 005c8823d9
2 changed files with 24 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/xml"
"errors"
"fmt"
"io"
"net"
"time"
@ -211,7 +212,7 @@ func (c *Client) Send(packet stanza.Packet) error {
return errors.New("cannot marshal packet " + err.Error())
}
return c.sendWithLogger(string(data))
return c.sendWithWriter(c.Session.streamLogger, data)
}
// SendRaw sends an XMPP stanza as a string to the server.
@ -224,12 +225,12 @@ func (c *Client) SendRaw(packet string) error {
return errors.New("client is not connected")
}
return c.sendWithLogger(packet)
return c.sendWithWriter(c.Session.streamLogger, []byte(packet))
}
func (c *Client) sendWithLogger(packet string) error {
func (c *Client) sendWithWriter(writer io.Writer, packet []byte) error {
var err error
_, err = fmt.Fprintf(c.Session.streamLogger, packet)
_, err = writer.Write(packet)
return err
}

19
client_internal_test.go Normal file
View File

@ -0,0 +1,19 @@
package xmpp
import (
"bytes"
"testing"
)
func TestClient_Send(t *testing.T) {
buffer := bytes.NewBufferString("")
client := Client{}
data := []byte("https://da.wikipedia.org/wiki/J%C3%A6vnd%C3%B8gn")
if err := client.sendWithWriter(buffer, data); err != nil {
t.Errorf("Writing failed: %v", err)
}
if buffer.String() != string(data) {
t.Errorf("Incorrect value sent to buffer: '%s'", buffer.String())
}
}