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

attribute matching inside at-form #142

Open
juhofriman opened this issue Feb 6, 2017 · 1 comment
Open

attribute matching inside at-form #142

juhofriman opened this issue Feb 6, 2017 · 1 comment

Comments

@juhofriman
Copy link

Hi,

I don't know if this is a bug or by design, but this one caused me some weirdness so I decided to write a brief report on this. If this is by design, just close this issue please :)

If given html contains attribute already, it looks like attr= is matched as string directly.

; Following does not match because (not (= 1 "1"))
user=> (sniptest "<div dummy=\"1\"></div>" [(attr= :dummy 1)] (content "matching"))
"<div dummy=\"1\"></div>"

; Following naturally matches
user=> (sniptest "<div dummy=\"1\"></div>" [(attr= :dummy "1")] (content "matching"))
"<div dummy=\"1\">matching</div>"

But if attribute is set inside transformation it retains type information during transformation.

; Setting dummy="1" (as number!) inside transformation and refering to it as number
user=> (sniptest "<div dummy=\"1\"></div>" [:div] (set-attr :dummy 1) [(attr= :dummy 1)] (content "matching"))
"<div dummy=\"1\">matching</div>"

; But if it is referenced as string, it of course does not match
user=> (sniptest "<div dummy=\"1\"></div>" [:div] (set-attr :dummy 1) [(attr= :dummy "1")] (content "matching"))
"<div dummy=\"1\"></div>"

Bottom line is that setting an attribute as number effectively creates dummy="1" which is then again read as a string. I think this in an inconsistency but I do acknowledge this can be by design as well.

Because attributes in xml do not really have type information I would suggest that matching would always be done as arguments interpreted as strings. But I really don't know all the details. If this is an inconsistency I can even try to put on a pull request.

Loving enlive and using it daily! :)

@cgrand
Copy link
Owner

cgrand commented Feb 6, 2017 via email

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

2 participants