mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2009-10-26 03:02 am

[dw-free] Logic for checking format=light/style=mine, etc arguments is duplicated in various places

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

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

Add function to validate style, s2id, and format args and then pass them
back in a ready to use URL form.

Patch by [personal profile] afuna.

Files modified:
  • cgi-bin/weblib.pl
--------------------------------------------------------------------------------
diff -r 8d0176156a61 -r 19b03e6b9ecd cgi-bin/weblib.pl
--- a/cgi-bin/weblib.pl	Mon Oct 26 02:57:10 2009 +0000
+++ b/cgi-bin/weblib.pl	Mon Oct 26 03:02:28 2009 +0000
@@ -993,6 +993,27 @@ sub set_lastcomment
 
 sub deemp {
     "<span class='de'>$_[0]</span>";
+}
+
+=head2 C<< LJ::viewing_style_args( %arguments ) >>
+Takes a list of viewing styles arguments from a list, makes sure they are valid values,
+and returns them as a string that can be appended to the URL. Looks for "s2id", "format", "style"
+=cut
+sub viewing_style_args {
+    my ( %args ) = @_;
+    my $valid_style_args = {
+        format => { light => 1 },
+        style  => { light => 1, style => 1, site => 1, mine => 1 },
+    };
+    
+    my @valid_args;
+    # only accept purely numerical s2ids
+    push @valid_args, "s2id=$args{s2id}" if $args{s2id} && $args{s2id} =~ /^\d+$/;
+
+    foreach my $key ( qw( format style ) ) {
+         push @valid_args, "style=$args{$key}" if $valid_style_args->{$key}->{$args{$key}};
+    }
+    return join "&", @valid_args;
 }
 
 # <LJFUNC>
--------------------------------------------------------------------------------
afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)

[personal profile] afuna 2009-10-26 03:06 am (UTC)(link)
*eyes hash*

I'm not sure what I was thinking, but the valid_style_args says that "style=style". is valid.
afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)

[personal profile] afuna 2009-10-26 03:09 am (UTC)(link)
Ahaha. Oh well! *offers you a cookie*