Skip to content

Commit

Permalink
Fixed empty lines at end of dotEnv parsing (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
sliemeobn authored May 2, 2023
1 parent 8d84d77 commit a2b45b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Sources/Hummingbird/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ public struct HBEnvironment: Sendable, Decodable, ExpressibleByDictionaryLiteral

switch state {
case .readingKey:
// handle empty lines at the end
guard !parser.reachedEnd() else { break }

// check for comment
let c = parser.current()
if c == "#" {
Expand Down
11 changes: 11 additions & 0 deletions Tests/HummingbirdTests/EnvironmentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ final class EnvironmentTests: XCTestCase {
FOO=BAR
#BAZ=
"""
let result = try HBEnvironment.parseDotEnv(dotenv)
XCTAssertEqual(result["foo"], "BAR")
XCTAssertEqual(result.count, 1)
}

func testEmptyLineAtEnd() throws {
let dotenv = """
FOO=BAR
"""
let result = try HBEnvironment.parseDotEnv(dotenv)
XCTAssertEqual(result["foo"], "BAR")
Expand Down

0 comments on commit a2b45b9

Please sign in to comment.