[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
afuna.
Files modified:
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]](https://www.dreamwidth.org/img/silk/identity/user.png)
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> --------------------------------------------------------------------------------
no subject
I'm not sure what I was thinking, but the valid_style_args says that "style=style". is valid.
no subject
no subject