Compare commits

...
Author SHA1 Message Date
dependabot[bot] 183d87a874 Bump github/codeql-action from 4 to 4.37.4
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 4 to 4.37.4.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v4...v4.37.4)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 4.37.4
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-08-04 09:43:29 +00:00
John Barton 97a2850142 Merge pull request #265 from joho/ci/pin-windows-2025-vs2026
Point CI to new windows tag
2026-05-25 10:52:27 +10:00
John Barton e77328b146 Update the windows version per github warning.
"NOTICE: windows-latest requests are being redirected to windows-2025-vs2026 by June 15, 2028"
2026-05-25 10:37:27 +10:00
John Barton efa32f116f Merge pull request #264 from joho/fix/allow-hyphens-in-keys
Definitively commit to allowing hyphens (again)
2026-05-25 10:33:10 +10:00
John Barton 139cdfde14 Update readme to capture ruby/node key compatibililty 2026-05-25 10:30:10 +10:00
John Barton 87021fd05a test: drop stale parser-error case for hyphens in keys
PR #245 (commit 82194f2) widened the variable-name charset to include
'-', restoring v1.4.0 behaviour. The "Invalid char" case in
TestParserErrors predates that change and has been failing ever since;
CI only started surfacing it after the recent go.mod bump.

The deliberate "hyphens allowed" contract is already covered by
TestLoadHyphenEnv (positive) and TestKeyNameCharsetRejectsDisallowed
(negative lock-in on '+', '@', '/'), so removing this case is the
correct fix rather than reverting #245.
2026-05-25 10:11:01 +10:00
John Barton 32bfb2c280 Merge pull request #188 from joho/dependabot/github_actions/thatisuday/go-cross-build-1.1.0
Bump thatisuday/go-cross-build from 1.0.2 to 1.1.0
2026-05-20 14:21:31 +10:00
John Barton 17f409325c Bump go mod minimum version 2026-05-20 14:20:46 +10:00
Rohan Verma c92e518f6a tests: add unit tests for parser errors
- Declares errors and wraps them for error checking
by clients
- Adds two unit tests for
  - terminated quote error
  - unexpected char
2026-05-20 14:20:46 +10:00
John Barton 59ad2adcd3 Merge pull request #240 from ignatij/patch-1
docs: add usage for tool dependency in go1.24
2026-05-20 14:19:24 +10:00
John Barton 8680ef74f4 Merge pull request #263 from joho/ci-and-versioning-updates-may-26
CI and Versioning updates
2026-05-20 14:11:22 +10:00
ignatij fab96ba47b docs: add usage for tool dependency in go1.24 2025-02-19 15:25:32 +01:00
dependabot[bot] 892a220300 Bump thatisuday/go-cross-build from 1.0.2 to 1.1.0
Bumps [thatisuday/go-cross-build](https://github.com/thatisuday/go-cross-build) from 1.0.2 to 1.1.0.
- [Release notes](https://github.com/thatisuday/go-cross-build/releases)
- [Commits](https://github.com/thatisuday/go-cross-build/compare/v1.0.2...v1.1.0)

---
updated-dependencies:
- dependency-name: thatisuday/go-cross-build
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-13 09:58:14 +00:00
7 changed files with 49 additions and 9 deletions
+1 -1
View File
@@ -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
+3 -3
View File
@@ -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
+1 -1
View File
@@ -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'
+11
View File
@@ -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.
+1 -1
View File
@@ -1,3 +1,3 @@
module github.com/joho/godotenv
go 1.12
go 1.13
+22
View File
@@ -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)
}
})
}
}
+10 -3
View File
@@ -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 {