diff --git a/uiimg.go b/uiimg.go index 0c994dd..cbad1fc 100644 --- a/uiimg.go +++ b/uiimg.go @@ -11,23 +11,15 @@ type UiImg struct { StringSetter } -func (ui *UiImg) SrcAttr(e *Element) string { - src := ui.JawsGetString(e) - if len(src) < 1 || src[0] != '"' { - return strconv.Quote(src) - } - return src -} - func (ui *UiImg) JawsRender(e *Element, w io.Writer, params []any) error { ui.parseGetter(e, ui.StringSetter) - srcattr := template.HTMLAttr("src=" + ui.SrcAttr(e)) // #nosec G203 + srcattr := template.HTMLAttr("src=" + strconv.Quote(ui.JawsGetString(e))) // #nosec G203 attrs := append(e.ParseParams(params), srcattr) return WriteHtmlInner(w, e.Jid(), "img", "", "", attrs...) } -func (ui *UiImg) JawsUpdate(u *Element) { - u.SetAttr("src", ui.SrcAttr(u)) +func (ui *UiImg) JawsUpdate(e *Element) { + e.SetAttr("src", ui.JawsGetString(e)) } func NewUiImg(g StringSetter) *UiImg { diff --git a/uiimg_test.go b/uiimg_test.go index 89b662d..6832773 100644 --- a/uiimg_test.go +++ b/uiimg_test.go @@ -11,15 +11,15 @@ func TestRequest_Img(t *testing.T) { rq := newTestRequest() defer rq.Close() - ts := newTestSetter("\"quoted.png\"") + ts := newTestSetter("image.png") - wantHtml := "" + wantHtml := "" rq.Img(ts, "hidden") if gotHtml := rq.BodyString(); gotHtml != wantHtml { t.Errorf("Request.Img() = %q, want %q", gotHtml, wantHtml) } - ts.Set("unquoted.jpg") + ts.Set("image2.jpg") rq.Dirty(ts) select { @@ -27,7 +27,7 @@ func TestRequest_Img(t *testing.T) { th.Timeout() case msg := <-rq.outCh: s := msg.Format() - if s != "SAttr\tJid.1\t\"src\\n\\\"unquoted.jpg\\\"\"\n" { + if s != "SAttr\tJid.1\t\"src\\nimage2.jpg\"\n" { t.Error(strconv.Quote(s)) } }