Skip to content

empty safehtml.HTML is true, should be false #2

Open

Description

@jba

There is an incompatibility with html/template. The empty escaped template value template.HTML("") is false an in if, just as the empty string is. But the zero value safehtml.HTML{} is true.

See https://play.golang.org/p/iKB2uBICUX-.

Activity

  1. jba commented on Jun 30, 2020

    @jba
    Author

    I have a PR to fix template.IsTrue, but unfortunately I think fixing template execution is harder. The text/template execution engine is used, and it seems to have its version of IsTrue hardcoded.

    Probably best not to "fix" template.IsTrue if execution doesn't match it.

  2. jba commented on Jun 30, 2020

    @jba
    Author

    Maybe the best thing to do is to document clearly that if .X was previously a string or template.HTML and is now a safehtml.HTML or other safehtml type, one must replace

    {{if .X}}
    

    with

    {{if .X.String}}
    
  3. added
    bug
    documentation
    on Jul 6, 2020
  4. 5psf commented on Jul 6, 2020

    @5psf
    Collaborator

    Thanks for flagging this, we'll take a look at possible solutions, although at the moment updating the documentation seems the most probable outcome. safehtml/template tries to be as close to a drop-in replacement as possible, but the migration will never be 100% transparent, and this could be another of those divergences.

    Probably best not to "fix" template.IsTrue if execution doesn't match it.

    +1 for having a uniform behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdocumentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions