Skip to content

Commit e49ab60

Browse files
committed
Fix a bug in xml encoding and decoding
1 parent 0c5bb5d commit e49ab60

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

irods/message/xml.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import (
1010

1111
var (
1212
// escapes from xml.Encode
13-
escQuot = []byte(""") // shorter than """, \"
14-
escApos = []byte("'") // shorter than "'", \'
15-
escTab = []byte("	")
16-
escNL = []byte("
")
17-
escCR = []byte("
")
18-
escFFFD = []byte("\uFFFD") // Unicode replacement character
13+
escQuot = []byte(""") // shorter than """, \"
14+
escApos = []byte("'") // shorter than "'", \'
15+
escTab = []byte("	")
16+
escNL = []byte("
")
17+
escCR = []byte("
")
18+
escBacktick = []byte("`")
19+
escFFFD = []byte("\uFFFD") // Unicode replacement character
1920

2021
// escapes for irods
2122
irodsEscQuot = []byte(""")
@@ -122,6 +123,10 @@ func correctXMLRequest(in []byte, newXML bool) ([]byte, error) {
122123
out.WriteByte('\'')
123124
}
124125
buf = buf[len(escApos):]
126+
// turn ` into '
127+
case buf[0] == '`' && !newXML:
128+
out.Write(irodsEscApos)
129+
buf = buf[1:]
125130
// irods does not decode encoded tabs
126131
case bytes.HasPrefix(buf, escTab):
127132
out.WriteByte('\t')
@@ -134,10 +139,6 @@ func correctXMLRequest(in []byte, newXML bool) ([]byte, error) {
134139
case bytes.HasPrefix(buf, escNL):
135140
out.WriteByte('\n')
136141
buf = buf[len(escNL):]
137-
// turn ` into '
138-
case buf[0] == '`' && !newXML:
139-
out.Write(irodsEscApos)
140-
buf = buf[1:]
141142
// pass utf8 characters
142143
default:
143144
r, size := utf8.DecodeRune(buf)
@@ -203,12 +204,19 @@ func correctXMLResponse(in []byte, newXML bool) ([]byte, error) {
203204

204205
for len(buf) > 0 {
205206
switch {
206-
// turn " into `
207+
// turn " into "
207208
case bytes.HasPrefix(buf, irodsEscQuot) && !newXML:
208-
out.WriteByte('`')
209+
out.Write(escQuot)
209210
buf = buf[len(irodsEscQuot):]
210-
// turn ' into '
211-
case buf[0] == '\'' && !newXML:
211+
// turn ' into ' or `
212+
case bytes.HasPrefix(buf, irodsEscApos):
213+
if newXML {
214+
out.Write(escApos)
215+
} else {
216+
out.Write(escBacktick)
217+
}
218+
buf = buf[len(irodsEscApos):]
219+
case buf[0] == '\'':
212220
out.Write(escApos)
213221
buf = buf[1:]
214222
// check utf8 characters for validity

0 commit comments

Comments
 (0)