fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-08-22 08:30 am

[dw-free] Class names with "eval" unusable in CSS

[commit: http://hg.dwscoalition.org/dw-free/rev/fc856c03f49d]

http://bugs.dwscoalition.org/show_bug.cgi?id=2133

Add another class for posters / journals with "eval" in their username.
Example: class="poster-medieval" becomes class="poster-medievalb poster-
mediev-l", so that the element can still be targetted without causing the
CSS cleaner to choke on suspect CSS (that looks like Javascript)

Patch by [personal profile] rb.

Files modified:
  • bin/upgrading/s2layers/core2.s2
  • cgi-bin/LJ/S2.pm
--------------------------------------------------------------------------------
diff -r 8de9897c370d -r fc856c03f49d bin/upgrading/s2layers/core2.s2
--- a/bin/upgrading/s2layers/core2.s2	Mon Aug 22 16:16:02 2011 +0800
+++ b/bin/upgrading/s2layers/core2.s2	Mon Aug 22 16:26:01 2011 +0800
@@ -928,6 +928,9 @@
 function builtin pageview_unique_string () : string
 "Returns a unique string for the remote user.";
 
+function builtin clean_css_classname (string classname) : string
+"Provide a version of a string that's always suitable for classnames, with potentially suspicious words present in original and modified forms.";
+
 function builtin alternate (string a, string b) : string
 "With each call, this function will alternate between the two values and return one of them.
 Useful for making tables whose rows alternate in background color.";
@@ -4787,8 +4790,8 @@
     var string poster;
     var string journal;
     if ($this.journal.journal_type != "I") {
-        $poster = "poster-$this.poster.username";
-        $journal = "journal-$this.journal.username";
+        $poster = clean_css_classname( "poster-$this.poster.username" );
+        $journal = clean_css_classname( "journal-$this.journal.username" );
     }
     var string userpic = $this.userpic ? "has-userpic" : "no-userpic";
 
diff -r 8de9897c370d -r fc856c03f49d cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm	Mon Aug 22 16:16:02 2011 +0800
+++ b/cgi-bin/LJ/S2.pm	Mon Aug 22 16:26:01 2011 +0800
@@ -2579,6 +2579,21 @@
     return $scratch->{alternate}{"$one\0$two"} ? $one : $two;
 }
 
+sub clean_css_classname
+{
+    my ($ctx, $classname) = @_;
+    my $clean_classname;
+
+    if ($classname =~ /eval/) {
+        $clean_classname = $classname . " ";
+        $classname =~ s/eval/ev-l/g;
+        $clean_classname .= $classname;
+    } else {
+        $clean_classname = $classname;
+    }
+    return $clean_classname;
+}
+
 sub set_content_type
 {
     my ($ctx, $type) = @_;
--------------------------------------------------------------------------------
jeshyr: Blessed are the broken. Harry Potter. (Default)

[personal profile] jeshyr 2011-08-22 11:18 am (UTC)(link)
This is the bit where I do the embarrassing happy dance \o/
denise: Image: Me, facing away from camera, on top of the Castel Sant'Angelo in Rome (Default)

[staff profile] denise 2011-08-22 11:45 am (UTC)(link)
YAY YOUR FIRST PATCH YAY YAY YAY YAY OMG YAY

*\o/*

(that's a cheerleader with pompoms you know)
jeshyr: Blessed are the broken. Harry Potter. (Default)

[personal profile] jeshyr 2011-08-22 11:48 am (UTC)(link)
Thank you!!

I keep thinking "YAY!" and then self-censoring and Voice Of Authority says "but it wasn't anything significant, it's only small, your programming still sucks" and then I am practicing sitting on the Voice Of Authority and saying YAY some more :)
denise: Image: Me, facing away from camera, on top of the Castel Sant'Angelo in Rome (Default)

[staff profile] denise 2011-08-22 11:55 am (UTC)(link)
Oh, honey, it may be small, but I can testify that there are at least several people who will be doing cartwheels of joy when they see it in the code tour. Small improvements != insignificant improvements!

And besides, at least half of DW's awesomeness is in all the many, many, many small improvements we've made. We have a reptuation for being a site that cares about getting all the little details right, and that's a reputation I am very, very proud of. And bugs like this are a part of that! So pat yourself on the back, 'cause YOU MADE A THING and it's a thing people WANT and it will make people HAPPY.

(Also, nobody's programming skill sucks worse than mine. *G* I like to lead by example...)
jeshyr: Blessed are the broken. Harry Potter. (Default)

[personal profile] jeshyr 2011-08-22 12:03 pm (UTC)(link)
*glows* Thank you!!

It helps a lot that there's so many newbie coders actually, because I know I'd cheer for *you* or anybody else new who did a short patch like this - I'm fairly sure I have in the past - so it's easier to remember that I can deserve it too, y'know? The whole culture of support helps!! yay DW!
denise: Image: Me, facing away from camera, on top of the Castel Sant'Angelo in Rome (Default)

[staff profile] denise 2011-08-22 12:19 pm (UTC)(link)
Yes! It's one of the things I love most about DW (okay, there are many things I love most about DW, but still): the way we are so encouraging to people who are just starting out or just returning to coding or to OSS development after a long break. I think it's so awesome how friendly and supportive we are -- it never fails to make me feel like we're doing something super special awesome. I mean, we're kicking this much ass and we're teaching people how to code while we're doing it. That is just plain kickass of us.

In short, YOU ARE AWESOME. DW IS AWESOME. THE DW COMMUNITY IS AWESOME. THAT IS ALL.
jeshyr: Blessed are the broken. Harry Potter. (Default)

[personal profile] jeshyr 2011-08-22 12:32 pm (UTC)(link)
+1

:)
ninetydegrees: Art: girl in a superhero costume holding a pencil (superheroine)

Congrats!

[personal profile] ninetydegrees 2011-08-23 01:04 am (UTC)(link)
Small bugs FTW!

1) There are significant because the portion of users who waited for this to be fixed and thought it would fall into bug limbo because it's just a small, insignificant, low-priority bug will be ecstatic.

2) I always tell myself fixing the small stuff is important because it lets other devs concentrate on other bugs. Like we're all ants and everybody does its part and it makes us work better as a team. It doesn't mean we can't go from small to bigger and vice-versa but I think it's important there are always people working on all different kinds of bugs.

3) Bug fixed! That's significant in itself. *cheers*
jeshyr: Blessed are the broken. Harry Potter. (Default)

Re: Congrats!

[personal profile] jeshyr 2011-08-23 10:30 am (UTC)(link)
Thank you! Especially thank you for point "2" because that's the sort of reasoning that still works even when I am having a moment of "woe my contributions are vanishingly small!" and it's hard to believe in myself, if that makes sense.

DW is totally the supportive-est place ever!
pauamma: Cartooney crab wearing hot pink and acid green facemask holding drink with straw (Default)

[personal profile] pauamma 2011-09-12 09:28 pm (UTC)(link)
/me makes silly faces at the Voice Of Americauthority.
yvi: Kaylee half-smiling, looking very pretty (Default)

[personal profile] yvi 2011-08-22 04:13 pm (UTC)(link)
And we do a happy dance with you! \o/
jeshyr: Blessed are the broken. Harry Potter. (Default)

[personal profile] jeshyr 2011-08-23 10:30 am (UTC)(link)
Woot!!! DW is totally the supportive-est place ever!

:)
pne: A picture of a plush toy, halfway between a duck and a platypus, with a green body and a yellow bill and feet. (Default)

[personal profile] pne 2011-08-25 09:26 am (UTC)(link)
Hm, is "eval" the only thing that gets stripped by the CSS cleaner?

A quick google brought up this snippet which also checks for (among others), "behavior", "behaviour", and "expression", which also vaguely ring a bell for "active code in CSS" for me. (See lines 33-34 for more ideas - check against CSS cleaner.)

If those are also stripped, then poor users like "expression" or "badbehavior" will also have problems with CSS classes and will require a similar workaround/fix.
denise: Image: Me, facing away from camera, on top of the Castel Sant'Angelo in Rome (Default)

[staff profile] denise 2011-08-25 03:02 pm (UTC)(link)
We haven't gotten any complaints about any of the others, while we have gotten complaints about this.