aboutsummaryrefslogtreecommitdiff
path: root/src/path/example_test.go
diff options
context:
space:
mode:
authorAndrew Ekstedt <andrew.ekstedt@gmail.com>2020-07-24 12:48:30 -0700
committerRob Pike <r@golang.org>2020-08-19 00:10:22 +0000
commit98a0071a5363e307c2e284034f810378de3883dd (patch)
tree4da947f708d5ff763f0370e93b61c2eae1a63ba0 /src/path/example_test.go
parent0941fc3f9ff43598d25fa6e964e7829a268102bf (diff)
downloadgo-98a0071a5363e307c2e284034f810378de3883dd.tar.xz
path,path/filepath: add Join examples with ".." components
People sometimes expect Join to trim .. components from its arguments before joining, and are surprised that it doesn't. This is bad if they were relying on that assumed behaviour to prevent directory traversal attacks. While a careful reading of the documentation for Join and Clean might dispel this notion, it is not obvious at first glance. Add a case to the examples to nudge people in the right direction. Updates #40373 Change-Id: Ib5792c12ba1000811a0c0eb77048196d0b26da60 Reviewed-on: https://go-review.googlesource.com/c/go/+/249177 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/path/example_test.go')
-rw-r--r--src/path/example_test.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/path/example_test.go b/src/path/example_test.go
index 67b9718664..e30ebd13dc 100644
--- a/src/path/example_test.go
+++ b/src/path/example_test.go
@@ -79,13 +79,18 @@ func ExampleJoin() {
fmt.Println(path.Join("a", "b", "c"))
fmt.Println(path.Join("a", "b/c"))
fmt.Println(path.Join("a/b", "c"))
+
+ fmt.Println(path.Join("a/b", "../../../xyz"))
+
fmt.Println(path.Join("", ""))
fmt.Println(path.Join("a", ""))
fmt.Println(path.Join("", "a"))
+
// Output:
// a/b/c
// a/b/c
// a/b/c
+ // ../xyz
//
// a
// a