From c06d8a62c5f32b4c0a724785a213a06234f35372 Mon Sep 17 00:00:00 2001
From: Scott Moser
Date: Wed, 9 Oct 2019 16:02:33 -0400
Subject: [PATCH] Use SplitN rather than Split on os.Environ return value.
Environment variables can contain a '=' in their value
KEY=BAR=1 sh -c 'echo KEY VALUE is "$KEY"'
If you just use Split() then you may not actually get a 'pair'
but rather a slice with length >= 3.
---
examples/environment-variables/environment-variables.go | 2 +-
examples/environment-variables/environment-variables.hash | 4 ++--
public/environment-variables | 6 +++---
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/examples/environment-variables/environment-variables.go b/examples/environment-variables/environment-variables.go
index b316b8a..d1754a1 100644
--- a/examples/environment-variables/environment-variables.go
+++ b/examples/environment-variables/environment-variables.go
@@ -27,7 +27,7 @@ func main() {
// get the key and value. Here we print all the keys.
fmt.Println()
for _, e := range os.Environ() {
- pair := strings.Split(e, "=")
+ pair := strings.SplitN(e, "=", 2)
fmt.Println(pair[0])
}
}
diff --git a/examples/environment-variables/environment-variables.hash b/examples/environment-variables/environment-variables.hash
index b245851..e410038 100644
--- a/examples/environment-variables/environment-variables.hash
+++ b/examples/environment-variables/environment-variables.hash
@@ -1,2 +1,2 @@
-db2e203da519a22943753295e9cc27d89e4347b0
-bKuCOOD16KH
+b651bc17e4d2880cba0885c52f476ab2a86e39ae
+MTbfmZYa4vP
diff --git a/public/environment-variables b/public/environment-variables
index 25504ae..9920efd 100644
--- a/public/environment-variables
+++ b/public/environment-variables
@@ -44,7 +44,7 @@ Let’s look at how to set, get, and list environment variables.
- 
+ 
@@ -109,7 +109,7 @@ get the key and value. Here we print all the keys.
fmt.Println()
for _, e := range os.Environ() {
- pair := strings.Split(e, "=")
+ pair := strings.SplitN(e, "=", 2)
fmt.Println(pair[0])
}
}
@@ -186,7 +186,7 @@ program picks that value up.
|