Skip to content

Commit c23c69b

Browse files
committed
Fix bug when equal sign is inside env vars
1 parent bb9bf2d commit c23c69b

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ go-replace --mode=template daemon.conf
7979
## Installation
8080

8181
```bash
82-
GOREPLACE_VERSION=0.5.1 \
82+
GOREPLACE_VERSION=0.5.2 \
8383
&& wget -O /usr/local/bin/go-replace https://github.com/webdevops/goreplace/releases/download/$GOREPLACE_VERSION/gr-64-linux \
8484
&& chmod +x /usr/local/bin/go-replace
8585
```

goreplace.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
const (
1919
Author = "webdevops.io"
20-
Version = "0.5.1"
20+
Version = "0.5.2"
2121
)
2222

2323
type changeset struct {
@@ -431,7 +431,11 @@ func generateTemplateData(changesets []changeset) (templateData) {
431431
// add env variables
432432
for _, e := range os.Environ() {
433433
pair := strings.Split(e, "=")
434-
ret.Env[pair[0]] = pair[1]
434+
435+
envKey := pair[0]
436+
envValue := strings.Join(pair[1:], "=")
437+
438+
ret.Env[envKey] = envValue
435439
}
436440

437441
return ret

tests/main.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,27 @@ Testing template mode with only env and empty var:
417417
this is the last line
418418

419419

420+
Testing template mode with only env and empty var:
421+
422+
$ cat > test.txt <<EOF
423+
> {{23 -}} < {{- 45}}
424+
> {{.Env.Foobar}}
425+
> this is a testline
426+
> this is the second line
427+
> this is the third foobar line
428+
> this is the last line
429+
> EOF
430+
$ Foobar="bar=foo" goreplace --mode=template test.txt
431+
$ cat test.txt
432+
23<45
433+
bar=foo
434+
this is a testline
435+
this is the second line
436+
this is the third foobar line
437+
this is the last line
438+
439+
440+
420441
Testing template mode:
421442

422443
$ cat > test.txt <<EOF

0 commit comments

Comments
 (0)