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

[dw-free] Make user tags in icon email notifications work

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

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

Smartly clean, rather than just stripping all HTML.

Patch by [personal profile] fu.

Files modified:
  • cgi-bin/LJ/Event/NewUserpic.pm
--------------------------------------------------------------------------------
diff -r cc44ea023fcc -r 408139f766b9 cgi-bin/LJ/Event/NewUserpic.pm
--- a/cgi-bin/LJ/Event/NewUserpic.pm	Tue Apr 19 18:15:56 2011 +0800
+++ b/cgi-bin/LJ/Event/NewUserpic.pm	Tue Apr 19 18:37:01 2011 +0800
@@ -38,6 +38,20 @@ sub as_html {
     return $self->event_journal->ljuser_display . " has uploaded a new <a href='" . $up->url . "'>icon</a>.";
 }
 
+sub _clean_field {
+    my ( $field, %opts ) = @_;
+
+    LJ::CleanHTML::clean( \$field, {
+        wordlength => 40,
+        addbreaks => 0,
+        tablecheck => 1,
+        mode => "deny",
+        textonly => $opts{textonly},
+    } );
+
+    return $field;
+}
+
 sub as_email_string {
     my ($self, $u) = @_;
     return unless $self->userpic && $self->userpic->valid;
@@ -45,8 +59,8 @@ sub as_email_string {
     my $username = $u->user;
     my $poster = $self->userpic->owner->user;
     my $userpic = $self->userpic->url;
-    my $comment = LJ::strip_html( $self->userpic->comment ) || '(none)';
-    my $description = LJ::strip_html( $self->userpic->description ) || '(none)';
+    my $comment = _clean_field( $self->userpic->comment, textonly => 1 ) || '(none)';
+    my $description = _clean_field( $self->userpic->description, textonly => 1 ) || '(none)';
     my $journal_url = $self->userpic->owner->journal_base;
     my $icons_url = $self->userpic->owner->allpics_base;
     my $profile = $self->userpic->owner->profile_url;
@@ -92,8 +106,9 @@ sub as_email_html {
     my $poster = $self->userpic->owner->ljuser_display;
     my $postername = $self->userpic->owner->user;
     my $userpic = $self->userpic->imgtag;
-    my $comment = LJ::ehtml( $self->userpic->comment ) || '(none)';
-    my $description = LJ::ehtml( $self->userpic->description ) || '(none)';
+
+    my $comment = _clean_field( $self->userpic->comment, textonly => 0 ) || '(none)';
+    my $description = _clean_field( $self->userpic->description, textonly => 0 ) || '(none)';
     my $journal_url = $self->userpic->owner->journal_base;
     my $icons_url = $self->userpic->owner->allpics_base;
     my $profile = $self->userpic->owner->profile_url;
--------------------------------------------------------------------------------