mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-23 13:59:09 +02:00
[client] Stop the URL redaction from eating the prose after the URL
The class `[^\s"']+` ran past every delimiter that is not whitespace or a quote,
so a URL followed by `)`, `>` or a backtick took the closing character and the
words after it into the match, and everything past the small TrimRight set was
dropped from the message:
(see https://upload.example.com/x?t=1) for details
-> (see https://upload.example.com for details
Stop the match at those delimiters and leave TrimRight to sentence punctuation.
Three cases added.
Reported by cubic on #7514.
This commit is contained in:
@@ -38,7 +38,7 @@ func TestRedactURLsInError(t *testing.T) {
|
||||
{
|
||||
// The presigned PUT URL is the one that carries credentials.
|
||||
name: "presigned URL loses its credentials",
|
||||
err: errors.New(`upload failed: Put "https://bucket.s3.amazonaws.com/k?X-Amz-Signature=abc123&X-Amz-Credential=AKIA": timeout`),
|
||||
err: errors.New(`upload failed: Put "https://bucket.s3.amazonaws.com/k?X-Amz-Signature=abc123&X-Amz-Credential=AKIA": timeout`),
|
||||
want: `upload failed: Put "https://bucket.s3.amazonaws.com": timeout`,
|
||||
},
|
||||
{
|
||||
@@ -51,6 +51,23 @@ func TestRedactURLsInError(t *testing.T) {
|
||||
err: errors.New(`redirect from https://a.example.com/x?t=1 to https://b.example.com/y?t=2`),
|
||||
want: `redirect from https://a.example.com to https://b.example.com`,
|
||||
},
|
||||
{
|
||||
// The match must stop at the delimiter, not run on and eat the
|
||||
// words after it.
|
||||
name: "closing paren and the prose after it survive",
|
||||
err: errors.New(`(see https://upload.example.com/x?t=1) for details`),
|
||||
want: `(see https://upload.example.com) for details`,
|
||||
},
|
||||
{
|
||||
name: "angle brackets survive",
|
||||
err: errors.New(`tried <https://a.example.com/p?q=1> and failed`),
|
||||
want: `tried <https://a.example.com> and failed`,
|
||||
},
|
||||
{
|
||||
name: "backticks survive",
|
||||
err: errors.New("use `https://b.example.com/p` instead"),
|
||||
want: "use `https://b.example.com` instead",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
|
||||
Reference in New Issue
Block a user