mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-07-13 13:46:28 +00:00
Update dependencies (#1841)
This commit is contained in:
10
vendor/github.com/subosito/gotenv/.travis.yml
generated
vendored
10
vendor/github.com/subosito/gotenv/.travis.yml
generated
vendored
@ -1,10 +0,0 @@
|
||||
language: go
|
||||
go:
|
||||
- 1.x
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
script:
|
||||
- go test -test.v -coverprofile=coverage.out -covermode=count
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
11
vendor/github.com/subosito/gotenv/CHANGELOG.md
generated
vendored
11
vendor/github.com/subosito/gotenv/CHANGELOG.md
generated
vendored
@ -1,5 +1,16 @@
|
||||
# Changelog
|
||||
|
||||
## [1.3.0] - 2022-05-23
|
||||
|
||||
### Added
|
||||
|
||||
- Support = within double-quoted strings
|
||||
- Add support for multiline values
|
||||
|
||||
### Changed
|
||||
|
||||
- `OverLoad` prefer environment variables over local variables
|
||||
|
||||
## [1.2.0] - 2019-08-03
|
||||
|
||||
### Added
|
||||
|
7
vendor/github.com/subosito/gotenv/README.md
generated
vendored
7
vendor/github.com/subosito/gotenv/README.md
generated
vendored
@ -1,12 +1,11 @@
|
||||
# gotenv
|
||||
|
||||
[](https://travis-ci.org/subosito/gotenv)
|
||||
[](https://ci.appveyor.com/project/subosito/gotenv/branch/master)
|
||||
[](https://github.com/subosito/gotenv/actions)
|
||||
[](https://codecov.io/gh/subosito/gotenv)
|
||||
[](https://goreportcard.com/report/github.com/subosito/gotenv)
|
||||
[](https://godoc.org/github.com/subosito/gotenv)
|
||||
|
||||
Load environment variables dynamically in Go.
|
||||
Load environment variables from `.env` or `io.Reader` in Go.
|
||||
|
||||
## Usage
|
||||
|
||||
@ -120,7 +119,7 @@ Just in case you want to parse environment variables from any `io.Reader`, goten
|
||||
pairs := gotenv.Parse(strings.NewReader("FOO=test\nBAR=$FOO"))
|
||||
// gotenv.Env{"FOO": "test", "BAR": "test"}
|
||||
|
||||
err, pairs = gotenv.StrictParse(strings.NewReader(`FOO="bar"`))
|
||||
pairs, err := gotenv.StrictParse(strings.NewReader(`FOO="bar"`))
|
||||
// gotenv.Env{"FOO": "bar"}
|
||||
```
|
||||
|
||||
|
9
vendor/github.com/subosito/gotenv/appveyor.yml
generated
vendored
9
vendor/github.com/subosito/gotenv/appveyor.yml
generated
vendored
@ -1,9 +0,0 @@
|
||||
build: off
|
||||
clone_folder: c:\gopath\src\github.com\subosito\gotenv
|
||||
environment:
|
||||
GOPATH: c:\gopath
|
||||
stack: go 1.10
|
||||
before_test:
|
||||
- go get -t
|
||||
test_script:
|
||||
- go test -v -cover -race
|
127
vendor/github.com/subosito/gotenv/gotenv.go
generated
vendored
127
vendor/github.com/subosito/gotenv/gotenv.go
generated
vendored
@ -16,6 +16,9 @@ const (
|
||||
|
||||
// Pattern for detecting valid variable within a value
|
||||
variablePattern = `(\\)?(\$)(\{?([A-Z0-9_]+)?\}?)`
|
||||
|
||||
// Byte order mark character
|
||||
bom = "\xef\xbb\xbf"
|
||||
)
|
||||
|
||||
// Env holds key/value pair of valid environment variable
|
||||
@ -84,7 +87,7 @@ func loadenv(override bool, filenames ...string) error {
|
||||
|
||||
// parse and set :)
|
||||
func parset(r io.Reader, override bool) error {
|
||||
env, err := StrictParse(r)
|
||||
env, err := strictParse(r, override)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -110,7 +113,7 @@ func setenv(key, val string, override bool) {
|
||||
// It expands the value of a variable from the environment variable but does not set the value to the environment itself.
|
||||
// This function is skipping any invalid lines and only processing the valid one.
|
||||
func Parse(r io.Reader) Env {
|
||||
env, _ := StrictParse(r)
|
||||
env, _ := strictParse(r, false)
|
||||
return env
|
||||
}
|
||||
|
||||
@ -118,22 +121,59 @@ func Parse(r io.Reader) Env {
|
||||
// It expands the value of a variable from the environment variable but does not set the value to the environment itself.
|
||||
// This function is returning an error if there are any invalid lines.
|
||||
func StrictParse(r io.Reader) (Env, error) {
|
||||
return strictParse(r, false)
|
||||
}
|
||||
|
||||
func strictParse(r io.Reader, override bool) (Env, error) {
|
||||
env := make(Env)
|
||||
scanner := bufio.NewScanner(r)
|
||||
|
||||
i := 1
|
||||
bom := string([]byte{239, 187, 191})
|
||||
firstLine := true
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
|
||||
if i == 1 {
|
||||
if firstLine {
|
||||
line = strings.TrimPrefix(line, bom)
|
||||
firstLine = false
|
||||
}
|
||||
|
||||
i++
|
||||
if line == "" || line[0] == '#' {
|
||||
continue
|
||||
}
|
||||
|
||||
err := parseLine(line, env)
|
||||
quote := ""
|
||||
idx := strings.Index(line, "=")
|
||||
if idx == -1 {
|
||||
idx = strings.Index(line, ":")
|
||||
}
|
||||
if idx > 0 && idx < len(line)-1 {
|
||||
val := strings.TrimSpace(line[idx+1:])
|
||||
if val[0] == '"' || val[0] == '\'' {
|
||||
quote = val[:1]
|
||||
idx = strings.LastIndex(strings.TrimSpace(val[1:]), quote)
|
||||
if idx >= 0 && val[idx] != '\\' {
|
||||
quote = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
for quote != "" && scanner.Scan() {
|
||||
l := scanner.Text()
|
||||
line += "\n" + l
|
||||
idx := strings.LastIndex(l, quote)
|
||||
if idx > 0 && l[idx-1] == '\\' {
|
||||
continue
|
||||
}
|
||||
if idx >= 0 {
|
||||
quote = ""
|
||||
}
|
||||
}
|
||||
|
||||
if quote != "" {
|
||||
return env, fmt.Errorf("missing quotes")
|
||||
}
|
||||
|
||||
err := parseLine(line, env, override)
|
||||
if err != nil {
|
||||
return env, err
|
||||
}
|
||||
@ -142,9 +182,14 @@ func StrictParse(r io.Reader) (Env, error) {
|
||||
return env, nil
|
||||
}
|
||||
|
||||
func parseLine(s string, env Env) error {
|
||||
rl := regexp.MustCompile(linePattern)
|
||||
rm := rl.FindStringSubmatch(s)
|
||||
var (
|
||||
lineRgx = regexp.MustCompile(linePattern)
|
||||
unescapeRgx = regexp.MustCompile(`\\([^$])`)
|
||||
varRgx = regexp.MustCompile(variablePattern)
|
||||
)
|
||||
|
||||
func parseLine(s string, env Env, override bool) error {
|
||||
rm := lineRgx.FindStringSubmatch(s)
|
||||
|
||||
if len(rm) == 0 {
|
||||
return checkFormat(s, env)
|
||||
@ -153,35 +198,36 @@ func parseLine(s string, env Env) error {
|
||||
key := rm[1]
|
||||
val := rm[2]
|
||||
|
||||
// trim whitespace
|
||||
val = strings.TrimSpace(val)
|
||||
|
||||
// determine if string has quote prefix
|
||||
hdq := strings.HasPrefix(val, `"`)
|
||||
|
||||
// determine if string has single quote prefix
|
||||
hsq := strings.HasPrefix(val, `'`)
|
||||
|
||||
// trim whitespace
|
||||
val = strings.Trim(val, " ")
|
||||
|
||||
// remove quotes '' or ""
|
||||
rq := regexp.MustCompile(`\A(['"])(.*)(['"])\z`)
|
||||
val = rq.ReplaceAllString(val, "$2")
|
||||
if l := len(val); (hsq || hdq) && l >= 2 {
|
||||
val = val[1 : l-1]
|
||||
}
|
||||
|
||||
if hdq {
|
||||
val = strings.Replace(val, `\n`, "\n", -1)
|
||||
val = strings.Replace(val, `\r`, "\r", -1)
|
||||
val = strings.ReplaceAll(val, `\n`, "\n")
|
||||
val = strings.ReplaceAll(val, `\r`, "\r")
|
||||
|
||||
// Unescape all characters except $ so variables can be escaped properly
|
||||
re := regexp.MustCompile(`\\([^$])`)
|
||||
val = re.ReplaceAllString(val, "$1")
|
||||
val = unescapeRgx.ReplaceAllString(val, "$1")
|
||||
}
|
||||
|
||||
rv := regexp.MustCompile(variablePattern)
|
||||
fv := func(s string) string {
|
||||
return varReplacement(s, hsq, env)
|
||||
return varReplacement(s, hsq, env, override)
|
||||
}
|
||||
|
||||
val = rv.ReplaceAllStringFunc(val, fv)
|
||||
val = parseVal(val, env)
|
||||
if !hsq {
|
||||
val = varRgx.ReplaceAllStringFunc(val, fv)
|
||||
val = parseVal(val, env, hdq, override)
|
||||
}
|
||||
|
||||
env[key] = val
|
||||
return nil
|
||||
@ -201,7 +247,9 @@ func parseExport(st string, env Env) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func varReplacement(s string, hsq bool, env Env) string {
|
||||
var varNameRgx = regexp.MustCompile(`(\$)(\{?([A-Z0-9_]+)\}?)`)
|
||||
|
||||
func varReplacement(s string, hsq bool, env Env, override bool) string {
|
||||
if strings.HasPrefix(s, "\\") {
|
||||
return strings.TrimPrefix(s, "\\")
|
||||
}
|
||||
@ -210,9 +258,7 @@ func varReplacement(s string, hsq bool, env Env) string {
|
||||
return s
|
||||
}
|
||||
|
||||
sn := `(\$)(\{?([A-Z0-9_]+)\}?)`
|
||||
rn := regexp.MustCompile(sn)
|
||||
mn := rn.FindStringSubmatch(s)
|
||||
mn := varNameRgx.FindStringSubmatch(s)
|
||||
|
||||
if len(mn) == 0 {
|
||||
return s
|
||||
@ -220,6 +266,10 @@ func varReplacement(s string, hsq bool, env Env) string {
|
||||
|
||||
v := mn[3]
|
||||
|
||||
if replace, ok := os.LookupEnv(v); ok && !override {
|
||||
return replace
|
||||
}
|
||||
|
||||
replace, ok := env[v]
|
||||
if !ok {
|
||||
replace = os.Getenv(v)
|
||||
@ -242,21 +292,14 @@ func checkFormat(s string, env Env) error {
|
||||
return fmt.Errorf("line `%s` doesn't match format", s)
|
||||
}
|
||||
|
||||
func parseVal(val string, env Env) string {
|
||||
if strings.Contains(val, "=") {
|
||||
if !(val == "\n" || val == "\r") {
|
||||
kv := strings.Split(val, "\n")
|
||||
func parseVal(val string, env Env, ignoreNewlines bool, override bool) string {
|
||||
if strings.Contains(val, "=") && !ignoreNewlines {
|
||||
kv := strings.Split(val, "\r")
|
||||
|
||||
if len(kv) == 1 {
|
||||
kv = strings.Split(val, "\r")
|
||||
}
|
||||
|
||||
if len(kv) > 1 {
|
||||
val = kv[0]
|
||||
|
||||
for i := 1; i < len(kv); i++ {
|
||||
parseLine(kv[i], env)
|
||||
}
|
||||
if len(kv) > 1 {
|
||||
val = kv[0]
|
||||
for _, l := range kv[1:] {
|
||||
_ = parseLine(l, env, override)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user