[config] update glide dependencies
This commit is contained in:
1 parent
8e8b6d60f0
commit
a13722eec1
9 files changed
+128
-56
No files matched your search
+7
-1
@@ -118,9 +118,15 @@ Contributions are most welcome! The parser itself is pretty stupidly naive and I
|
||||
4. Push to the branch (`git push origin my-new-feature`)
|
||||
5. Create new Pull Request
|
||||
|
||||
## Releases
|
||||
|
||||
Releases should follow [Semver](http://semver.org/) though the first couple of releases are `v1` and `v1.1`.
|
||||
|
||||
Use [annotated tags for all releases](https://github.com/joho/godotenv/issues/30). Example `git tag -a v1.2.1`
|
||||
|
||||
## CI
|
||||
|
||||
Linux: [](https://app.wercker.com/project/bykey/507594c2ec7e60f19403a568dfea0f78) Windows: [](https://ci.appveyor.com/project/joho/godotenv)
|
||||
Linux: [](https://travis-ci.org/joho/godotenv) Windows: [](https://ci.appveyor.com/project/joho/godotenv)
|
||||
|
||||
## Who?
|
||||
|
||||
|
||||
+22
-13
@@ -25,6 +25,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const doubleQuoteSpecialChars = "\\\n\r\"!$`"
|
||||
|
||||
// Load will read your env file(s) and load them into ENV for this process.
|
||||
//
|
||||
// Call this function as close as possible to the start of your program (ideally in main)
|
||||
@@ -93,6 +95,11 @@ func Read(filenames ...string) (envMap map[string]string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// ReadString parses an environment file from dotenv file contents returning it as a map
|
||||
func ReadString(content string) (envMap map[string]string, err error) {
|
||||
return read(strings.NewReader(content))
|
||||
}
|
||||
|
||||
// Exec loads env vars from the specified filenames (empty map falls back to default)
|
||||
// then executes the cmd specified.
|
||||
//
|
||||
@@ -171,14 +178,10 @@ func readFile(filename string) (envMap map[string]string, err error) {
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
return ReadFromReader(file)
|
||||
return read(file)
|
||||
}
|
||||
|
||||
func readString(content string) (envMap map[string]string, err error) {
|
||||
return ReadFromReader(strings.NewReader(content))
|
||||
}
|
||||
|
||||
func ReadFromReader(r io.Reader) (envMap map[string]string, err error) {
|
||||
func read(r io.Reader) (envMap map[string]string, err error) {
|
||||
envMap = make(map[string]string)
|
||||
|
||||
var lines []string
|
||||
@@ -243,7 +246,7 @@ func parseLine(line string) (key string, value string, err error) {
|
||||
}
|
||||
|
||||
if len(splitString) != 2 {
|
||||
err = errors.New("Can't separate key from value for line: " + line)
|
||||
err = errors.New("Can't separate key from value")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -264,8 +267,8 @@ func parseValue(value string) string {
|
||||
// trim
|
||||
value = strings.Trim(value, " ")
|
||||
|
||||
// check if we've got quoted values
|
||||
if value != "" {
|
||||
// check if we've got quoted values or possible escapes
|
||||
if len(value) > 1 {
|
||||
first := string(value[0:1])
|
||||
last := string(value[len(value)-1:])
|
||||
if first == last && strings.ContainsAny(first, `"'`) {
|
||||
@@ -296,9 +299,15 @@ func isIgnoredLine(line string) bool {
|
||||
}
|
||||
|
||||
func doubleQuoteEscape(line string) string {
|
||||
line = strings.Replace(line, `\`, `\\`, -1)
|
||||
line = strings.Replace(line, "\n", `\n`, -1)
|
||||
line = strings.Replace(line, "\r", `\r`, -1)
|
||||
line = strings.Replace(line, `"`, `\"`, -1)
|
||||
for _, c := range doubleQuoteSpecialChars {
|
||||
toReplace := "\\" + string(c)
|
||||
if c == '\n' {
|
||||
toReplace = `\n`
|
||||
}
|
||||
if c == '\r' {
|
||||
toReplace = `\r`
|
||||
}
|
||||
line = strings.Replace(line, string(c), toReplace, -1)
|
||||
}
|
||||
return line
|
||||
}
|
||||
+8
-4
@@ -254,6 +254,10 @@ func TestParsing(t *testing.T) {
|
||||
parseAndCompare(t, `FOO="bar\\\n\ b\az"`, "FOO", "bar\\\n baz")
|
||||
parseAndCompare(t, `FOO="bar\\r\ b\az"`, "FOO", "bar\\r baz")
|
||||
|
||||
parseAndCompare(t, `="value"`, "", "value")
|
||||
parseAndCompare(t, `KEY="`, "KEY", "\"")
|
||||
parseAndCompare(t, `KEY="value`, "KEY", "\"value")
|
||||
|
||||
// it 'throws an error if line format is incorrect' do
|
||||
// expect{env('lol$wut')}.to raise_error(Dotenv::FormatError)
|
||||
badlyFormattedLine := "lol$wut"
|
||||
@@ -309,7 +313,7 @@ func TestErrorParsing(t *testing.T) {
|
||||
|
||||
func TestWrite(t *testing.T) {
|
||||
writeAndCompare := func(env string, expected string) {
|
||||
envMap, _ := readString(env)
|
||||
envMap, _ := ReadString(env)
|
||||
actual, _ := WriteString(envMap)
|
||||
if expected != actual {
|
||||
t.Errorf("Expected '%v' (%v) to write as '%v', got '%v' instead.", env, envMap, expected, actual)
|
||||
@@ -324,8 +328,8 @@ func TestWrite(t *testing.T) {
|
||||
writeAndCompare(`key=va"lu"e`, `key="va\"lu\"e"`)
|
||||
//but single quotes are left alone
|
||||
writeAndCompare(`key=va'lu'e`, `key="va'lu'e"`)
|
||||
// newlines and backslashes are escaped
|
||||
writeAndCompare(`foo="ba\n\r\\r!"`, `foo="ba\n\r\\r!"`)
|
||||
// newlines, backslashes, and some other special chars are escaped
|
||||
writeAndCompare(`foo="$ba\n\r\\r!"`, `foo="\$ba\n\r\\r\!"`)
|
||||
}
|
||||
|
||||
func TestRoundtrip(t *testing.T) {
|
||||
@@ -340,7 +344,7 @@ func TestRoundtrip(t *testing.T) {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
roundtripped, err := readString(rep)
|
||||
roundtripped, err := ReadString(rep)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user