Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor changes #206

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
interval: "daily"
1 change: 0 additions & 1 deletion LICENCE
Original file line number Diff line number Diff line change
Expand Up @@ -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.

1 change: 0 additions & 1 deletion cmd/godotenv/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"flag"
"fmt"
"log"

"strings"

"github.com/joho/godotenv"
Expand Down
2 changes: 1 addition & 1 deletion fixtures/plain.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ OPTION_D =4
OPTION_E = 5
OPTION_F =
OPTION_G=
OPTION_H=1 2
OPTION_H=1 2
4 changes: 2 additions & 2 deletions godotenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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
}
17 changes: 4 additions & 13 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -231,21 +231,12 @@ 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 {
if r == '\n' || r == '\r' {
return true
}
return false
return r == '\n' || r == '\r'
}

var (
Expand Down