Skip to content

Commit 402a848

Browse files
committed
Escape html commands string
1 parent 724de59 commit 402a848

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

hub.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"encoding/json"
55
"fmt"
6+
"html"
67
"io"
78
"os"
89
"runtime"
@@ -40,22 +41,22 @@ var h = hub{
4041
}
4142

4243
const commands = `{
43-
"Commands": [
44-
"list",
45-
"open < portName > < baud > [bufferAlgorithm: ({default}, timed, timedraw, timedbinary)]",
46-
"send < portName > < cmd >",
47-
"sendnobuf < portName > < cmd >",
48-
"close < portName >",
49-
"restart",
50-
"exit",
51-
"killupload",
52-
"downloadtool < tool > < toolVersion: {latest} > < pack: {arduino} > < behaviour: {keep} >",
53-
"log",
54-
"memorystats",
55-
"gc",
56-
"hostname",
57-
"version"
58-
]
44+
"Commands": [
45+
"list",
46+
"open <portName> <baud> [bufferAlgorithm: ({default}, timed, timedraw, timedbinary)]",
47+
"send <portName> <cmd>",
48+
"sendnobuf <portName> <cmd>",
49+
"close <portName>",
50+
"restart",
51+
"exit",
52+
"killupload",
53+
"downloadtool <tool> <toolVersion: {latest}> <pack: {arduino}> <behaviour: {keep}>",
54+
"log",
55+
"memorystats",
56+
"gc",
57+
"hostname",
58+
"version"
59+
]
5960
}`
6061

6162
func (h *hub) unregisterConnection(c *connection) {
@@ -86,7 +87,7 @@ func (h *hub) run() {
8687
h.connections[c] = true
8788
// send supported commands
8889
c.send <- []byte(fmt.Sprintf(`{"Version" : "%s"} `, version))
89-
c.send <- []byte(commands)
90+
c.send <- []byte(html.EscapeString(commands))
9091
c.send <- []byte(fmt.Sprintf(`{"Hostname" : "%s"} `, *hostname))
9192
c.send <- []byte(fmt.Sprintf(`{"OS" : "%s"} `, runtime.GOOS))
9293
case c := <-h.unregister:

0 commit comments

Comments
 (0)