Skip to content

Should all hrefs require templ.SafeURL to be consistent? #1091

@drognisep

Description

@drognisep

Before you begin

  • Please make sure you're using the latest version of the templ CLI (go install github.com/a-h/templ/cmd/templ@latest), and have upgraded your project to use the latest version of the templ runtime (go get -u github.com/a-h/templ@latest)
    • I tried using the latest CLI and runtime version, and I'm seeing the same behavior.

Describe the bug

First off, I'm not sure if this is a bug. I would expect that a link's href attribute would require a templ.SafeURL to be consistent with an anchor tag, but it seems to require a string instead.

I'm using a couple functions to add a URL path prefix to templ templates, and I noticed that static assets in the head element referenced by link allow (actually require due to how it's generated) a string.

One function returns a string (intended for HTMX attributes), and another returns a templ.SafeURL. I'm using the first variant without issue in link hrefs.

To Reproduce

Add a link element to a template (rel icon or stylesheet is what I'm seeing), and pass a plain Go string in curly braces ({}). There doesn't seem to be any requirement for a templ.SafeURL.

This is how I've produced this.

Expected behavior

I'd expect consistent behavior between hrefs for different elements, but there could be a good reason for the current behavior that I don't know about.

Edit: Trimming down text for clarity and adding specific links.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions