From 83bfe3b1bf25021d0a33352bed12696f5abe420a Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Sat, 11 Apr 2020 15:38:51 -0700 Subject: [PATCH] doc/go1.15, net/url: document new method URL.Redacted Adds an entry in the Go1.15 release notes, but also adds an example test for URL.Redacted. Follow-up of CL 207082. Updates #37419 Change-Id: Ibf81989778907511a3a3a3e4a03d1802b5dd9762 Reviewed-on: https://go-review.googlesource.com/c/go/+/227997 Run-TryBot: Emmanuel Odeke Reviewed-by: Ian Lance Taylor TryBot-Result: Gobot Gobot --- doc/go1.15.html | 10 ++++++++++ src/net/url/example_test.go | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/doc/go1.15.html b/doc/go1.15.html index e75132bfa74..8d74c9a5c14 100644 --- a/doc/go1.15.html +++ b/doc/go1.15.html @@ -134,6 +134,16 @@

Minor changes to the library

+
net/url
+
+

+ The new URL + method Redacted + returns the URL in string form with any password replaced with xxxxx. +

+
+
+
runtime

diff --git a/src/net/url/example_test.go b/src/net/url/example_test.go index ad67f5328a8..f0d3d2bf45d 100644 --- a/src/net/url/example_test.go +++ b/src/net/url/example_test.go @@ -205,6 +205,21 @@ func ExampleURL_UnmarshalBinary() { // https://example.org/foo } +func ExampleURL_Redacted() { + u := &url.URL{ + Scheme: "https", + User: url.UserPassword("user", "password"), + Host: "example.com", + Path: "foo/bar", + } + fmt.Println(u.Redacted()) + u.User = url.UserPassword("me", "newerPassword") + fmt.Println(u.Redacted()) + // Output: + // https://user:xxxxx@example.com/foo/bar + // https://me:xxxxx@example.com/foo/bar +} + func ExampleURL_RequestURI() { u, err := url.Parse("https://example.org/path?foo=bar") if err != nil {