From 6c5096f06a433fcb731d847caf2e91f978d45661 Mon Sep 17 00:00:00 2001 From: Randy Cahyana Date: Thu, 16 Feb 2017 16:37:39 +0700 Subject: [PATCH] Fixing SetAttributes --- query.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/query.go b/query.go index 2bc54e9..a4406d9 100644 --- a/query.go +++ b/query.go @@ -7,6 +7,7 @@ import ( "fmt" "image" "image/png" + "strconv" "strings" "sync" @@ -219,11 +220,11 @@ func SetAttributes(sel interface{}, attributes map[string]string, opts ...QueryO return errors.New("expected at least one element") } - attrs := make([]string, len(attributes)*2) + attrs := make([]string, len(attributes)) i := 0 for k, v := range attributes { - attrs[i], attrs[i+1] = k, v - i += 2 + attrs[i] = fmt.Sprintf(`%s=%s`, k, strconv.Quote(v)) + i++ } return dom.SetAttributesAsText(nodes[0].NodeID, strings.Join(attrs, " ")).Do(ctxt, h)