Skip to content

Commit 996c768

Browse files
support setting query parameters to undef
This allows for $uri->query(undef) to properly clear the query string, rather than leaving the previous value of 'pairs' intact
1 parent 8f5bca9 commit 996c768

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/Mojo/Parameters.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ sub parse {
110110
return $self->append(@_) if @_ > 1;
111111

112112
# String
113-
$self->{string} = shift;
113+
$self->{string} = shift // '';
114114
return $self;
115115
}
116116

t/mojo/parameters.t

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,12 @@ subtest 'Unicode' => sub {
178178
subtest 'Reparse' => sub {
179179
my $params = Mojo::Parameters->new('foo=bar&baz=23');
180180
$params->parse('foo=bar&baz=23');
181-
is "$params", 'foo=bar&baz=23', 'right result';
181+
is "$params", 'foo=bar&baz=23', 'right string result after assigning new string';
182+
is_deeply $params->pairs, ['foo', 'bar', 'baz', '23'], 'right pairs after assigning new string';
183+
184+
$params->parse(undef);
185+
is "$params", '', 'right result after assigning undef string';
186+
is_deeply $params->pairs, [], 'right pairs after assigning undef string';
182187
};
183188

184189
subtest 'Replace' => sub {

0 commit comments

Comments
 (0)