Commit 71d87fd8 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 340226: Util.pm shouldn't depend on Bugzilla::Config - Patch by Frédéric…

Bug 340226: Util.pm shouldn't depend on Bugzilla::Config - Patch by Frédéric Buclin <LpSolit@gmail.com> r=mkanat a=justdave
parent 825740c6
...@@ -44,7 +44,6 @@ use base qw(Exporter); ...@@ -44,7 +44,6 @@ use base qw(Exporter);
bz_crypt generate_random_password bz_crypt generate_random_password
validate_email_syntax clean_text); validate_email_syntax clean_text);
use Bugzilla::Config;
use Bugzilla::Constants; use Bugzilla::Constants;
use Date::Parse; use Date::Parse;
...@@ -269,7 +268,7 @@ sub find_wrap_point { ...@@ -269,7 +268,7 @@ sub find_wrap_point {
sub perform_substs { sub perform_substs {
my ($str, $substs) = (@_); my ($str, $substs) = (@_);
$str =~ s/%([a-z]*)%/(defined $substs->{$1} ? $substs->{$1} : Param($1))/eg; $str =~ s/%([a-z]*)%/(defined $substs->{$1} ? $substs->{$1} : Bugzilla->params->{$1})/eg;
return $str; return $str;
} }
...@@ -295,7 +294,8 @@ sub format_time { ...@@ -295,7 +294,8 @@ sub format_time {
} }
else { else {
# Search for %Z or %z, meaning we want the timezone to be displayed. # Search for %Z or %z, meaning we want the timezone to be displayed.
# Till bug 182238 gets fixed, we assume Param('timezone') is used. # Till bug 182238 gets fixed, we assume Bugzilla->params->{'timezone'}
# is used.
$show_timezone = ($format =~ s/\s?%Z$//i); $show_timezone = ($format =~ s/\s?%Z$//i);
} }
...@@ -304,7 +304,7 @@ sub format_time { ...@@ -304,7 +304,7 @@ sub format_time {
if (defined $time) { if (defined $time) {
$date = time2str($format, $time); $date = time2str($format, $time);
$date .= " " . &::Param('timezone') if $show_timezone; $date .= " " . Bugzilla->params->{'timezone'} if $show_timezone;
} }
else { else {
# Don't let invalid (time) strings to be passed to templates! # Don't let invalid (time) strings to be passed to templates!
...@@ -365,7 +365,7 @@ sub generate_random_password { ...@@ -365,7 +365,7 @@ sub generate_random_password {
sub validate_email_syntax { sub validate_email_syntax {
my ($addr) = @_; my ($addr) = @_;
my $match = Param('emailregexp'); my $match = Bugzilla->params->{'emailregexp'};
my $ret = ($addr =~ /$match/ && $addr !~ /[\\\(\)<>&,;:"\[\] \t\r\n]/); my $ret = ($addr =~ /$match/ && $addr !~ /[\\\(\)<>&,;:"\[\] \t\r\n]/);
return $ret ? 1 : 0; return $ret ? 1 : 0;
} }
...@@ -406,7 +406,7 @@ sub get_netaddr { ...@@ -406,7 +406,7 @@ sub get_netaddr {
my $addr = unpack("N", pack("CCCC", split(/\./, $ipaddr))); my $addr = unpack("N", pack("CCCC", split(/\./, $ipaddr)));
my $maskbits = Param('loginnetmask'); my $maskbits = Bugzilla->params->{'loginnetmask'};
# Make Bugzilla ignore the IP address if loginnetmask is set to 0 # Make Bugzilla ignore the IP address if loginnetmask is set to 0
return "0.0.0.0" if ($maskbits == 0); return "0.0.0.0" if ($maskbits == 0);
...@@ -579,9 +579,9 @@ in a command-line script. ...@@ -579,9 +579,9 @@ in a command-line script.
=item C<get_netaddr($ipaddr)> =item C<get_netaddr($ipaddr)>
Given an IP address, this returns the associated network address, using Given an IP address, this returns the associated network address, using
C<Param('loginnetmask')> as the netmask. This can be used to obtain data C<Bugzilla->params->{'loginnetmask'}> as the netmask. This can be used
in order to restrict weak authentication methods (such as cookies) to to obtain data in order to restrict weak authentication methods (such as
only some addresses. cookies) to only some addresses.
=back =back
......
...@@ -28,18 +28,16 @@ use lib 't'; ...@@ -28,18 +28,16 @@ use lib 't';
use Support::Files; use Support::Files;
BEGIN { BEGIN {
use Test::More tests => 14; use Test::More tests => 15;
use_ok(Bugzilla);
use_ok(Bugzilla::Util); use_ok(Bugzilla::Util);
} }
# We need to override the the Param() function so we can get an expected # We need to override Bugzilla->params so we can get an expected value when
# value when Bugzilla::Utim::format_time calls asks for Param('timezone'). # Bugzilla::Util::format_time() calls ask for the 'timezone' parameter.
# This will also prevent the tests from failing on site that do not have a # This will also prevent the tests from failing on site that do not have a
# data/params file containing Param('timezone') yet. # data/params file containing 'timezone' yet.
sub myParam { Bugzilla->params->{'timezone'} = "TEST";
return "TEST" if $_[0] eq 'timezone';
}
*::Param = *myParam;
# we don't test the taint functions since that's going to take some more work. # we don't test the taint functions since that's going to take some more work.
# XXX: test taint functions # XXX: test taint functions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment