dhcp4: ensure MQTT topic names are printable (for mosquitto_sub)
This commit is contained in:
parent
3834acfa2b
commit
cbadfe5128
@ -34,6 +34,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"github.com/gokrazy/gokrazy"
|
"github.com/gokrazy/gokrazy"
|
||||||
"github.com/google/renameio"
|
"github.com/google/renameio"
|
||||||
@ -419,6 +420,15 @@ func newSrv(permDir string) (*srv, error) {
|
|||||||
// MQTT requires valid UTF-8 and some brokers don’t cope well with
|
// MQTT requires valid UTF-8 and some brokers don’t cope well with
|
||||||
// invalid UTF-8: https://github.com/fhmq/hmq/issues/104
|
// invalid UTF-8: https://github.com/fhmq/hmq/issues/104
|
||||||
identifier := strings.ToValidUTF8(latest.Hostname, "")
|
identifier := strings.ToValidUTF8(latest.Hostname, "")
|
||||||
|
// Some MQTT clients (e.g. mosquitto_pub) don’t cope well with topic
|
||||||
|
// names containing non-printable characters (see also
|
||||||
|
// https://twitter.com/zekjur/status/1347295676909158400):
|
||||||
|
identifier = strings.Map(func(r rune) rune {
|
||||||
|
if unicode.IsPrint(r) {
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}, identifier)
|
||||||
if identifier == "" {
|
if identifier == "" {
|
||||||
identifier = latest.HardwareAddr
|
identifier = latest.HardwareAddr
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user