You've already forked woodpecker
							
							
				mirror of
				https://github.com/woodpecker-ci/woodpecker.git
				synced 2025-10-30 23:27:39 +02:00 
			
		
		
		
	Escape newlines in env var substitution
This commit is contained in:
		| @@ -8,6 +8,7 @@ import ( | ||||
| 	"math/rand" | ||||
| 	"regexp" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/gin-gonic/gin" | ||||
| @@ -461,7 +462,11 @@ func (b *builder) Build() ([]*buildItem, error) { | ||||
|  | ||||
| 		y := b.Yaml | ||||
| 		s, err := envsubst.Eval(y, func(name string) string { | ||||
| 			return environ[name] | ||||
| 			env := environ[name] | ||||
| 			if strings.Contains(env, "\n") { | ||||
| 				env = fmt.Sprintf("%q", env) | ||||
| 			} | ||||
| 			return env | ||||
| 		}) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
|   | ||||
							
								
								
									
										31
									
								
								server/hook_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								server/hook_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
| package server | ||||
|  | ||||
| import ( | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/drone/drone/model" | ||||
| ) | ||||
|  | ||||
| func TestMultilineEnvsubst(t *testing.T) { | ||||
| 	b := builder{ | ||||
| 		Repo: &model.Repo{}, | ||||
| 		Curr: &model.Build{ | ||||
| 			Message: `aaa | ||||
| bbb`, | ||||
| 		}, | ||||
| 		Last: &model.Build{}, | ||||
| 		Netrc: &model.Netrc{}, | ||||
| 		Secs: []*model.Secret{}, | ||||
| 		Regs: []*model.Registry{}, | ||||
| 		Link: "", | ||||
| 		Yaml: `pipeline: | ||||
|   xxx: | ||||
|     image: scratch | ||||
|     yyy: ${DRONE_COMMIT_MESSAGE} | ||||
| `, | ||||
| 	} | ||||
|  | ||||
| 	if _, err := b.Build(); err != nil { | ||||
| 		t.Fatal(err) | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user