From 71f02e081e86dd32a7a151ec92a6295a943162f6 Mon Sep 17 00:00:00 2001 From: 2tef <21069422+2tef@users.noreply.github.com> Date: Fri, 3 Feb 2023 21:45:46 -0300 Subject: [PATCH 1/6] simplify isSpace() --- parser.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/parser.go b/parser.go index cc709af..ef7cf75 100644 --- a/parser.go +++ b/parser.go @@ -231,14 +231,8 @@ func isCharFunc(char rune) func(rune) bool { } // isSpace reports whether the rune is a space character but not line break character -// -// this differs from unicode.IsSpace, which also applies line break as space func isSpace(r rune) bool { - switch r { - case '\t', '\v', '\f', '\r', ' ', 0x85, 0xA0: - return true - } - return false + return unicode.IsSpace(r) && r != '\n' } func isLineEnd(r rune) bool { From 24fce42adb8f4e58c9cc157a2e946222ebbbe150 Mon Sep 17 00:00:00 2001 From: 2tef <21069422+2tef@users.noreply.github.com> Date: Mon, 6 Feb 2023 18:58:55 -0300 Subject: [PATCH 2/6] fix whitespace --- .github/dependabot.yml | 2 +- LICENCE | 1 - cmd/godotenv/cmd.go | 1 - fixtures/plain.env | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 6151c64..e28e858 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,4 +7,4 @@ updates: - package-ecosystem: "github-actions" directory: "/" schedule: - interval: "daily" \ No newline at end of file + interval: "daily" diff --git a/LICENCE b/LICENCE index e7ddd51..9390caf 100644 --- a/LICENCE +++ b/LICENCE @@ -20,4 +20,3 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/cmd/godotenv/cmd.go b/cmd/godotenv/cmd.go index 2a7b2d8..7ad0a50 100644 --- a/cmd/godotenv/cmd.go +++ b/cmd/godotenv/cmd.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "log" - "strings" "github.com/joho/godotenv" diff --git a/fixtures/plain.env b/fixtures/plain.env index e033366..4c341c8 100644 --- a/fixtures/plain.env +++ b/fixtures/plain.env @@ -5,4 +5,4 @@ OPTION_D =4 OPTION_E = 5 OPTION_F = OPTION_G= -OPTION_H=1 2 \ No newline at end of file +OPTION_H=1 2 From b7238207545de52403dcc1c893166a2b4ea5974b Mon Sep 17 00:00:00 2001 From: 2tef <21069422+2tef@users.noreply.github.com> Date: Mon, 6 Feb 2023 19:02:10 -0300 Subject: [PATCH 3/6] simplify isLineEnd() --- parser.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/parser.go b/parser.go index ef7cf75..b914cd2 100644 --- a/parser.go +++ b/parser.go @@ -236,10 +236,7 @@ func isSpace(r rune) bool { } func isLineEnd(r rune) bool { - if r == '\n' || r == '\r' { - return true - } - return false + return r == '\n' || r == '\r' } var ( From efc42c84e3435bfcad80d8a30aa784a965882f34 Mon Sep 17 00:00:00 2001 From: 2tef <21069422+2tef@users.noreply.github.com> Date: Mon, 6 Feb 2023 19:10:34 -0300 Subject: [PATCH 4/6] remove unnecessary assignment --- godotenv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/godotenv.go b/godotenv.go index 61b0ebb..5acfa97 100644 --- a/godotenv.go +++ b/godotenv.go @@ -196,7 +196,7 @@ func loadFile(filename string, overload bool) error { for key, value := range envMap { if !currentEnv[key] || overload { - _ = os.Setenv(key, value) + os.Setenv(key, value) } } From f738024474e412ab77bb4b26f9f94b07149315f1 Mon Sep 17 00:00:00 2001 From: 2tef <21069422+2tef@users.noreply.github.com> Date: Wed, 8 Feb 2023 20:40:50 -0300 Subject: [PATCH 5/6] use ReplaceAll() instead of Replace(..., -1) --- godotenv.go | 2 +- parser.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/godotenv.go b/godotenv.go index 5acfa97..5478e20 100644 --- a/godotenv.go +++ b/godotenv.go @@ -222,7 +222,7 @@ func doubleQuoteEscape(line string) string { if c == '\r' { toReplace = `\r` } - line = strings.Replace(line, string(c), toReplace, -1) + line = strings.ReplaceAll(line, string(c), toReplace) } return line } diff --git a/parser.go b/parser.go index b914cd2..ab20c81 100644 --- a/parser.go +++ b/parser.go @@ -18,7 +18,7 @@ const ( ) func parseBytes(src []byte, out map[string]string) error { - src = bytes.Replace(src, []byte("\r\n"), []byte("\n"), -1) + src = bytes.ReplaceAll(src, []byte("\r\n"), []byte("\n")) cutset := src for { cutset = getStatementStart(cutset) From 24346f7f7d154d5194f8bf63500219d1cbfdbbb8 Mon Sep 17 00:00:00 2001 From: 2tef <21069422+2tef@users.noreply.github.com> Date: Wed, 8 Feb 2023 20:42:34 -0300 Subject: [PATCH 6/6] fix function name in doc comment --- parser.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser.go b/parser.go index ab20c81..fd2cae7 100644 --- a/parser.go +++ b/parser.go @@ -44,7 +44,7 @@ func parseBytes(src []byte, out map[string]string) error { return nil } -// getStatementPosition returns position of statement begin. +// getStatementStart returns position of statement begin. // // It skips any comment line or non-whitespace character. func getStatementStart(src []byte) []byte {