agl / xmpp-client

An XMPP client with OTR support
BSD 3-Clause "New" or "Revised" License
365 stars 71 forks source link

UTF-8 support. #39

Closed schulze closed 11 years ago

schulze commented 11 years ago

(This is again a go.crypto/ssh/terminal limitation, but I will put this here because I find it a problem only regarding xmpp-client.)

Terminal input currently is ASCII only. My äöü and ß keys are just dead. This is not a big problem for german text, but certainly for most non-european languages.

agl commented 11 years ago

Can you

1) Run strace -f -e read xmpp-client 2) Wait for the handshake to complete 3) Enter some of those keys and note in this bug what bytes are read from the terminal for them.

I'm not sure what the mapping from UTF-8 code point to terminal bytes is, but I'm sure that, with a couple of examples, it'll be clear.

schulze commented 11 years ago

äöüß in this order gives

[pid 25938] read(0, "\303\244", 256)    = 2
[pid 25938] read(0, "\303\266", 256)    = 2
[pid 25938] read(0, "\303\274", 256)    = 2
[pid 25938] read(0, "\303\237", 256)    = 2

This are exactly the 2-byte UTF-8 codes for the characters (http://www.utf8-chartable.de/unicode-utf8-table.pl?utf8=oct ).

schulze commented 11 years ago

Just say your go.crypto/ssh/terminal patch https://codereview.appspot.com/13704043/ I will take the liberty to close this.

schulze commented 11 years ago

Of course, I should have checked, that xmpp-client doesn't need a patch too.

agl commented 11 years ago

Please let me know if I've broken anything.

schulze commented 11 years ago

Thanks for working on this!

Sending non-ASCII text, using up-arrow to go back once in the history and then backspace gives

panic: runtime error: slice bounds out of range

goroutine 5 [running]:
code.google.com/p/go.crypto/ssh/terminal.(*Terminal).eraseNPreviousChars(0xc21006d000, 0x1)
    /home/schulze/g/src/code.google.com/p/go.crypto/ssh/terminal/terminal.go:306 +0x45f
code.google.com/p/go.crypto/ssh/terminal.(*Terminal).handleKey(0xc21006d000, 0x7f, 0x0, 0x0, 0xc21006d000)
    /home/schulze/g/src/code.google.com/p/go.crypto/ssh/terminal/terminal.go:370 +0x34f
code.google.com/p/go.crypto/ssh/terminal.(*Terminal).readLine(0xc21006d000, 0x0, 0x0, 0x0, 0x0)
    /home/schulze/g/src/code.google.com/p/go.crypto/ssh/terminal/terminal.go:602 +0x792
code.google.com/p/go.crypto/ssh/terminal.(*Terminal).ReadLine(0xc21006d000, 0x0, 0x0, 0x0, 0x0)
    /home/schulze/g/src/code.google.com/p/go.crypto/ssh/terminal/terminal.go:578 +0xb1
main.(*Input).ProcessCommands(0xc210205f18, 0xc210039540)
    /home/schulze/g/src/github.com/agl/xmpp-client/input.go:348 +0x268
created by main.main
    /home/schulze/g/src/github.com/agl/xmpp-client/ui.go:317 +0x1854

goroutine 1 [select]:
main.main()
    /home/schulze/g/src/github.com/agl/xmpp-client/ui.go:331 +0x55a0

goroutine 4 [syscall]:
runtime.goexit()
    /home/schulze/Src/go/src/pkg/runtime/proc.c:1386

goroutine 6 [IO wait]:
net.runtime_pollWait(0x7fd8c3d80538, 0x72, 0x0)
    /home/schulze/Src/go/src/pkg/runtime/netpoll.goc:116 +0x6a
net.(*pollDesc).Wait(0xc210047450, 0x72, 0x0, 0x0)
    /home/schulze/Src/go/src/pkg/net/fd_poll_runtime.go:81 +0x4c
net.(*pollDesc).WaitRead(0xc210047450, 0x0, 0x0)
    /home/schulze/Src/go/src/pkg/net/fd_poll_runtime.go:86 +0x42
net.(*netFD).Read(0xc2100473f0, 0xc21008bc00, 0x400, 0x400, 0x0, ...)
    /home/schulze/Src/go/src/pkg/net/fd_unix.go:208 +0x31a
net.(*conn).Read(0xc210000500, 0xc21008bc00, 0x400, 0x400, 0x0, ...)
    /home/schulze/Src/go/src/pkg/net/net.go:123 +0xe7
crypto/tls.(*block).readFromUntil(0xc21001ef00, 0x7fd8c3d80948, 0xc210000500, 0x5, 0x0, ...)
    /home/schulze/Src/go/src/pkg/crypto/tls/conn.go:459 +0x110
crypto/tls.(*Conn).readRecord(0xc21000ba00, 0x17, 0x0, 0x0)
    /home/schulze/Src/go/src/pkg/crypto/tls/conn.go:539 +0x163
crypto/tls.(*Conn).Read(0xc21000ba00, 0xc21020a000, 0x1000, 0x1000, 0x0, ...)
    /home/schulze/Src/go/src/pkg/crypto/tls/conn.go:897 +0x18d
io.(*teeReader).Read(0xc2102571e0, 0xc21020a000, 0x1000, 0x1000, 0x0, ...)
    /home/schulze/Src/go/src/pkg/io/io.go:485 +0x9f
bufio.(*Reader).fill(0xc2101bfc60)
    /home/schulze/Src/go/src/pkg/bufio/bufio.go:91 +0x1a5
bufio.(*Reader).ReadByte(0xc2101bfc60, 0x0, 0x0, 0x0)
    /home/schulze/Src/go/src/pkg/bufio/bufio.go:183 +0xc5
encoding/xml.(*Decoder).getc(0xc210248c80, 0x0)
    /home/schulze/Src/go/src/pkg/encoding/xml/xml.go:845 +0xc8
encoding/xml.(*Decoder).rawToken(0xc210248c80, 0x0, 0x0, 0x0, 0x0)
    /home/schulze/Src/go/src/pkg/encoding/xml/xml.go:505 +0x1ae
encoding/xml.(*Decoder).Token(0xc210248c80, 0x0, 0x0, 0x0, 0x0)
    /home/schulze/Src/go/src/pkg/encoding/xml/xml.go:240 +0x84a
github.com/agl/xmpp.nextStart(0xc210248c80, 0x0, 0x0, 0x0, 0x0, ...)
    /home/schulze/g/src/github.com/agl/xmpp/xmpp.go:567 +0xa3
github.com/agl/xmpp.next(0xc210039120, 0x0, 0x0, 0x0, 0x0, ...)
    /home/schulze/g/src/github.com/agl/xmpp/xmpp.go:729 +0xb3
github.com/agl/xmpp.(*Conn).Next(0xc210039120, 0x0, 0x0, 0x0, 0x0, ...)
    /home/schulze/g/src/github.com/agl/xmpp/xmpp.go:80 +0xb0
main.(*Session).readMessages(0xc210205ee0, 0xc2101ee000)
    /home/schulze/g/src/github.com/agl/xmpp-client/ui.go:136 +0x76
created by main.main
    /home/schulze/g/src/github.com/agl/xmpp-client/ui.go:320 +0x189e
~ > 
agl commented 11 years ago

Should be fixed in https://codereview.appspot.com/13255050. If anyone wants to give a LGTM, I'll land that.

ln5 commented 11 years ago

Reproduced the panic, applied the two diffs, unable to reproduce panic.

Thanks for making this work! (7-bit ASCII is cool and all that, but some of my less geeky friends were starting to get annoyed with me. :)

schulze commented 11 years ago

The patches work fine for me. I also tried to give a LGTM.

agl commented 11 years ago

Patch landed in go.crypto.