mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-06 05:29:07 +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:
@@ -178,8 +178,12 @@ func getURLHash(url string) string {
|
||||
return fmt.Sprintf("%x", sha256.Sum256([]byte(url)))
|
||||
}
|
||||
|
||||
// urlInText matches an absolute http(s) URL inside a free-form message.
|
||||
var urlInText = regexp.MustCompile(`https?://[^\s"']+`)
|
||||
// urlInText matches an absolute http(s) URL inside a free-form message. The
|
||||
// class stops at the delimiters an error message wraps a URL in — quotes,
|
||||
// backticks, angle brackets, parens and braces — so the match does not run past
|
||||
// the URL and swallow the prose after it. TrimRight below then drops trailing
|
||||
// sentence punctuation, which a bare URL at the end of a clause picks up.
|
||||
var urlInText = regexp.MustCompile("https?://[^\\s\"'`<>\\[\\]{}()]+")
|
||||
|
||||
// redactedError keeps the original error reachable for errors.Is/As while
|
||||
// presenting a message with every URL cut down to scheme://host.
|
||||
|
||||
Reference in New Issue
Block a user