Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Commit 9be7a7e

Browse files
committed
PERL-1118 - Improve URI stringify sanitization
1 parent 24f1f7c commit 9be7a7e

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

‎lib/MongoDB/_URI.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ sub __userinfo_invalid_chars {
655655
# redact user credentials when stringifying
656656
use overload
657657
'""' => sub {
658-
(my $s = $_[0]->uri) =~ s{^(\w+)://[^/]+\@}{1ドル://[**REDACTED**]\@};
658+
(my $s = $_[0]->uri) =~ s{^([^:]+)://[^/]+\@}{1ドル://[**REDACTED**]\@};
659659
return $s
660660
},
661661
'fallback' => 1;

‎t/unit/uri.t

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,21 @@ subtest "auth credentials" => sub {
279279
);
280280
};
281281

282+
subtest "stringification" => sub {
283+
# For srv uri parsing and tests, see uri_srv.t
284+
my $uri;
285+
286+
$uri = new_ok( $class, [ uri => 'mongodb://fred:foobar@localhost' ] );
287+
is( "$uri", 'mongodb://[**REDACTED**]@localhost', "stringify correct" );
288+
289+
$uri = new_ok( $class, [ uri => 'mongodb://:@localhost' ] );
290+
is( "$uri", 'mongodb://[**REDACTED**]@localhost', "stringify correct" );
291+
292+
$uri = new_ok( $class, [ uri => 'mongodb://@localhost' ] );
293+
is( "$uri", 'mongodb://@localhost', "stringify correct" );
294+
295+
$uri = new_ok( $class, [ uri => 'mongodb://localhost' ] );
296+
is( "$uri", 'mongodb://localhost', "stringify correct" );
297+
};
298+
282299
done_testing;

‎t/unit/uri_srv.t

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,23 @@ subtest "boolean params unchanged" => sub {
9090
is $sslVal, 'true', 'SSL true';
9191

9292
is $expires, 1, 'expires as expected';
93-
}
93+
};
94+
};
95+
96+
subtest "stringification" => sub {
97+
my $uri = new_ok( $class, [
98+
uri => 'mongodb+srv://testpass@testmongo.example.com',
99+
_test_seedlist_return => [
100+
[{ target => 'localhost', port => 27017 }],
101+
{
102+
retryWrites => 'true',
103+
retryReads => 'false',
104+
},
105+
0
106+
]
107+
]);
108+
109+
is "$uri", 'mongodb+srv://[**REDACTED**]@testmongo.example.com', 'Stringification for SRV urls correct';
94110
};
95111

96112
done_testing;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /