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>
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org