Unexpected behavior with CSS style binding

32 views
Skip to first unread message

Peter Brant

unread,
Aug 1, 2011, 11:47:53 AM8/1/11
to lif...@googlegroups.com
Hi all,

I've been treating "..." #> None and "..." #> "" as more or less
interchangeable, but it looks like this is not always true:

With 2.4-M3:

scala> ("#foo *" #> "")(<td id="foo"></td>)
res1: scala.xml.NodeSeq = NodeSeq(<td id="foo"></td>)

scala> ("#foo *" #> (None: Option[String]))(<td id="foo"></td>)
res2: scala.xml.NodeSeq = NodeSeq()

scala> ("#foo *" #> Nil)(<td id="foo"></td>)
res3: scala.xml.NodeSeq = NodeSeq(<td id="foo"></td>)

I would expect "#foo *" #> None to wipe out the <td>'s children, but
not remove the element itself. Does this make sense? If so, I'll
open a ticket for myself.

Pete

David Whittaker

unread,
Aug 1, 2011, 2:14:46 PM8/1/11
to lif...@googlegroups.com
For what it's worth, it makes sense to me.


--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.


Andreas Joseph Krogh

unread,
Aug 1, 2011, 4:08:11 PM8/1/11
to lif...@googlegroups.com

+1

I've encountered this oddity my self (2.4-M1) and agree that "#foo *" #>
None on a (<td id="foo"></td>) shouldn't wipe out the TD-element itself
but its children, in which this case is none, ie. leave the node-seq
un-altered.

--
Andreas Joseph Krogh <and...@officenet.no>
Senior Software Developer / CTO
Public key: http://home.officenet.no/~andreak/public_key.asc
------------------------+---------------------------------------------+
OfficeNet AS | The most difficult thing in the world is to |
Rosenholmveien 25 | know how to do a thing and to watch |
1414 Troll�sen | somebody else doing it wrong, without |
NORWAY | comment. |
Org.nr: NO 981 479 076 | |
| |
Tlf: +47 24 15 38 90 | |
Fax: +47 24 15 38 91 | |
Mobile: +47 909 56 963 | |
------------------------+---------------------------------------------+

David Pollak

unread,
Aug 3, 2011, 11:58:10 AM8/3/11
to lif...@googlegroups.com
Yeah... looks like a bug... please open a ticket.

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net

Peter Brant

unread,
Aug 29, 2011, 8:40:52 PM8/29/11
to lif...@googlegroups.com
There is a (WIP as it turns out) change for this up on the Review
Board [ http://reviewboard.liftweb.net/r/640/ ] now, but it's a bigger
can of worms than I'd thought. The existing behavior is documented as
expected. Comments from Review Board below:

... snip ...
There are a few examples in the original thread:
http://groups.google.com/group/liftweb/browse_thread/thread/ee2ec1146a79a550/

But, immediately after committing it occurred to me that this is a
pretty big change. Andreas noted that he didn't expect ("#foo *" #>
None)(<td id="foo"></td>) to wipe out the <td>, but I've often relied
on ("#foo *" #> Nil)(<td id="foo"></td>) to do exactly that.

My suggestion would be to make the suggested change for None, but keep
the existing behavior for Nil. We have a lot of transforms basically
identical to Andreas's example and need a lot of ugly getOrElse("")
calls to work around the current behavior.

That said, see the example at end of
http://simply.liftweb.net/index-7.10.html#toc-Section-7.10.

In short, this is more than just a bug fix and I think the argument
could be made to leave well enough alone too.
... snip ...

The proposed behavior makes more sense to me though.

Pete

Naftoli Gugenheim

unread,
Aug 29, 2011, 10:53:04 PM8/29/11
to lif...@googlegroups.com
I think the * means "don't affect the parent, only transform the children."
Personally I think the principle of least surprise is more important than not breaking code that relies on a bug.

Andreas Joseph Krogh

unread,
Aug 30, 2011, 2:37:06 AM8/30/11
to lif...@googlegroups.com
On Tue, Aug 30, 2011 at 4:53 AM, Naftoli Gugenheim <nafto...@gmail.com> wrote:
I think the * means "don't affect the parent, only transform the children."
Personally I think the principle of least surprise is more important than not breaking code that relies on a bug.

+1

According to the docs "<something> *" means exactly that (don't affect parent).

--
Andreas Joseph Krogh <and...@officenet.no>
Senior Software Developer / CTO
------------------------+---------------------------------------------+
OfficeNet AS            | The most difficult thing in the world is to |
Rosenholmveien 25       | know how to do a thing and to watch         |
1414 Trollåsen          | somebody else doing it wrong, without       |

Jeppe Nejsum Madsen

unread,
Aug 30, 2011, 3:12:44 AM8/30/11
to lif...@googlegroups.com
Naftoli Gugenheim <nafto...@gmail.com> writes:

> I think the * means "don't affect the parent, only transform the children."
> Personally I think the principle of least surprise is more important than
> not breaking code that relies on a bug.

Agreed

/Jeppe

David Pollak

unread,
Aug 30, 2011, 8:05:43 AM8/30/11
to lif...@googlegroups.com
I can't believe I missed this whole thread...

I agree that the behavior is incorrect and that the code on review board executes as the CSS Selector Transforms are defined.

Thanks for identifying and fixing this issue!
Reply all
Reply to author
Forward
0 new messages