Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty string as attribute name causes exception. #141

Open
Carlsson87 opened this issue Sep 13, 2018 · 7 comments
Open

Empty string as attribute name causes exception. #141

Carlsson87 opened this issue Sep 13, 2018 · 7 comments

Comments

@Carlsson87
Copy link

I just upgraded to version 1.0.1 and ran in to problems when using Html.attribute "" "". It didn't use to cause an exception, and now it does. Let me know if you need more info.

SSCCE: https://ellie-app.com/3kjwsTXvQNTa1

@norpan
Copy link

norpan commented Sep 13, 2018

Caused by d32f9b4

Probably fix would be to also check if attribute key is not empty, since that is not allowed.

@harrysarson
Copy link

Here is @Carlsson87's sscce:

module Main exposing (main)

import Html
import Html.Attributes

main =
    Html.div [ Html.Attributes.attribute "" "" ] [] 

@Carlsson87
Copy link
Author

To be extra specific. The problem seems to occur when the key is an empty string. The value being an empty string does not cause any problems for me.

@evancz
Copy link
Member

evancz commented Sep 13, 2018

Why are you doing this?

@Carlsson87
Copy link
Author

Carlsson87 commented Sep 13, 2018

When I conditionally want to set an attribute on an element. I use the same approach with Html.text "" when I want to conditionally render some elements.

showButton : Maybe msg -> Html msg
showButton clickMsg =
    Html.button
        [ case clickMsg of
            Just msg ->
                Html.Events.onClick msg
            Nothing ->
                Html.Attributes.attribute "" ""
        ]
        [ Html.text "Click here"
        ]

I'd love to know if there is a better way.

@hpate-omicron
Copy link
Contributor

hpate-omicron commented Sep 13, 2018

We use a similar pattern for conditional attributes, we have it defined as

none : Attribute msg
none =
    Html.Attributes.property "" Json.Encode.null

Which seems to be valid still https://ellie-app.com/3ks2h7XJWnTa1

@reiner-dolp
Copy link
Contributor

reiner-dolp commented Oct 14, 2018

@norpan how is d32f9b4 causing this bug? ah ok. I understand now. The bug was present before d32f9b4 for all cases Html.Attributes.attribute "" val except for val = "". Now using an empty string also triggers the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants