Skip to content

Commit 3878f9f

Browse files
committed
tags: fix escaped quotes
fixes: #3 closes: #2 closes: #5
1 parent 2fe4452 commit 3878f9f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

tags.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func (t *Tag) Value() string {
277277

278278
// String reassembles the tag into a valid tag field representation
279279
func (t *Tag) String() string {
280-
return fmt.Sprintf(`%s:"%s"`, t.Key, t.Value())
280+
return fmt.Sprintf(`%s:%q`, t.Key, t.Value())
281281
}
282282

283283
// GoString implements the fmt.GoStringer interface

tags_test.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ func TestParse(t *testing.T) {
151151
},
152152
},
153153
},
154+
{
155+
name: "tag with quoted name",
156+
tag: `json:"foo,bar:\"baz\""`,
157+
exp: []*Tag{
158+
{
159+
Key: "json",
160+
Name: "foo",
161+
Options: []string{`bar:"baz"`},
162+
},
163+
},
164+
},
154165
}
155166

156167
for _, ts := range test {
@@ -167,10 +178,13 @@ func TestParse(t *testing.T) {
167178
}
168179

169180
got := tags.Tags()
170-
171181
if !reflect.DeepEqual(ts.exp, got) {
172182
t.Errorf("parse\n\twant: %#v\n\tgot : %#v", ts.exp, got)
173183
}
184+
185+
if ts.tag != tags.String() {
186+
t.Errorf("parse string\n\twant: %#v\n\tgot : %#v", ts.tag, tags.String())
187+
}
174188
})
175189
}
176190
}

0 commit comments

Comments
 (0)