Skip to content

form action, anchor href should allow (SafeURL, error) #1167

@jackielii

Description

@jackielii

Before you begin

Release one hour ago:

templ version
v0.3.887

Describe the bug

form action and anchor href should allow (SafeURL, error), not just SafeURL

To Reproduce
A small, self-contained, complete reproduction, uploaded to a GitHub repo, containing the minimum amount of files required to reproduce the behaviour, along with a list of commands that need to be run. Keep it simple.

To reproduce, run templ generate on this example:

package main

import "errors"

templ hello() {
	<form action={ foo() }></form>
	<a href={ foo() }></a>
}

func foo() (templ.SafeURL, error) {
	return templ.URL("/foo"), errors.New("bar")
}

Expected behavior
A clear and concise description of what you expected to happen.

No compilation error, but instead the generated code assigns the result directly to one var:

		templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<form action=\"")
		if templ_7745c5c3_Err != nil {
			return templ_7745c5c3_Err
		}
		var templ_7745c5c3_Var2 templ.SafeURL = foo() <--- WRONG
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var2)))
		if templ_7745c5c3_Err != nil {
			return templ_7745c5c3_Err
		}
		templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "\"></form><a href=\"")
		if templ_7745c5c3_Err != nil {
			return templ_7745c5c3_Err
		}
		var templ_7745c5c3_Var3 templ.SafeURL = foo() <--- WRONG
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var3)))
		if templ_7745c5c3_Err != nil {
			return templ_7745c5c3_Err
		}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions