mirror of
https://github.com/joho/godotenv.git
synced 2026-12-03 20:39:11 +00:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
183d87a874 | ||
|
|
97a2850142 | ||
|
|
e77328b146 | ||
|
|
efa32f116f | ||
|
|
139cdfde14 | ||
|
|
87021fd05a | ||
|
|
32bfb2c280 | ||
|
|
17f409325c | ||
|
|
c92e518f6a | ||
|
|
59ad2adcd3 | ||
|
|
8680ef74f4 | ||
|
|
fab96ba47b | ||
|
|
892a220300 |
@@ -9,7 +9,7 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
go: [ '1.26', '1.25', '1.24', '1.23', '1.22' ]
|
||||
os: [ ubuntu-latest, macOS-latest, windows-latest ]
|
||||
os: [ ubuntu-latest, macOS-latest, windows-2025-vs2026 ]
|
||||
name: ${{ matrix.os }} Go ${{ matrix.go }} Tests
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
@@ -42,7 +42,7 @@ jobs:
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v4
|
||||
uses: github/codeql-action/init@v4.37.4
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
@@ -56,7 +56,7 @@ jobs:
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v4
|
||||
uses: github/codeql-action/autobuild@v4.37.4
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
||||
@@ -69,4 +69,4 @@ jobs:
|
||||
# ./location_of_script_within_repo/buildscript.sh
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v4
|
||||
uses: github/codeql-action/analyze@v4.37.4
|
||||
|
||||
@@ -13,7 +13,7 @@ jobs:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v6
|
||||
- name: Generate build files
|
||||
uses: thatisuday/go-cross-build@v1.0.2
|
||||
uses: thatisuday/go-cross-build@v1.1.0
|
||||
with:
|
||||
platforms: 'linux/amd64, linux/ppc64le, darwin/amd64, darwin/arm64, windows/amd64'
|
||||
package: 'cmd/godotenv'
|
||||
|
||||
@@ -20,6 +20,13 @@ As a library
|
||||
go get github.com/joho/godotenv
|
||||
```
|
||||
|
||||
as a tool dependency:
|
||||
|
||||
go >= 1.24
|
||||
```shell
|
||||
go get -tool github.com/joho/godotenv/cmd/godotenv
|
||||
```
|
||||
|
||||
or if you want to use it as a bin command
|
||||
|
||||
```shell
|
||||
@@ -112,6 +119,10 @@ content := getRemoteFileContent()
|
||||
myEnv, err := godotenv.Unmarshal(content)
|
||||
```
|
||||
|
||||
### Variable name compatibility
|
||||
|
||||
Ruby's dotenv only allows `[A-Za-z0-9_.]` in key names, while Node's dotenv also permits `-`. godotenv has matched the Node charset since v1.4.0, so keys like `MY-VAR` parse cleanly here and in Node but will error under Ruby's dotenv.
|
||||
|
||||
### Precedence & Conventions
|
||||
|
||||
Existing envs take precedence of envs that are loaded later.
|
||||
|
||||
@@ -2,6 +2,7 @@ package godotenv
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
@@ -703,3 +704,24 @@ func TestWhitespace(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParserErrors(t *testing.T) {
|
||||
cases := map[string]struct {
|
||||
input string
|
||||
err error
|
||||
}{
|
||||
"UnterminatedQuote": {
|
||||
input: "foo=\"bar",
|
||||
err: ErrUnterminatedQuote,
|
||||
},
|
||||
}
|
||||
|
||||
for n, c := range cases {
|
||||
t.Run(n, func(t *testing.T) {
|
||||
v, err := Unmarshal(c.input)
|
||||
if !errors.Is(err, c.err) {
|
||||
t.Errorf("Input: %q Expected:\t %q\nGot:\t %q Val: %v", c.input, c.err, err, v)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,12 @@ const (
|
||||
exportPrefix = "export"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrZeroLengthString = errors.New("zero length string")
|
||||
ErrUnexpectedChar = errors.New("unexpected character")
|
||||
ErrUnterminatedQuote = errors.New("unterminated quoted value")
|
||||
)
|
||||
|
||||
func parseBytes(src []byte, out map[string]string) error {
|
||||
src = bytes.ReplaceAll(src, []byte("\r\n"), []byte("\n"))
|
||||
cutset := src
|
||||
@@ -104,13 +110,14 @@ loop:
|
||||
}
|
||||
|
||||
return "", nil, fmt.Errorf(
|
||||
`unexpected character %q in variable name near %q`,
|
||||
`%w %q in variable name near %q`,
|
||||
ErrUnexpectedChar,
|
||||
string(char), string(src))
|
||||
}
|
||||
}
|
||||
|
||||
if len(src) == 0 {
|
||||
return "", nil, errors.New("zero length string")
|
||||
return "", nil, ErrZeroLengthString
|
||||
}
|
||||
|
||||
// trim whitespace
|
||||
@@ -193,7 +200,7 @@ func extractVarValue(src []byte, vars map[string]string) (value string, rest []b
|
||||
valEndIndex = len(src)
|
||||
}
|
||||
|
||||
return "", nil, fmt.Errorf("unterminated quoted value %s", src[:valEndIndex])
|
||||
return "", nil, fmt.Errorf("%w %s", ErrUnterminatedQuote, src[:valEndIndex])
|
||||
}
|
||||
|
||||
func expandEscapes(str string) string {
|
||||
|
||||
Reference in New Issue
Block a user