Skip to content

Commit

Permalink
Fix #63: Hard crash in MySQLData.description when a zero-value dateti…
Browse files Browse the repository at this point in the history
…me is received from older MySQL configurations which still do this. Returns a description of the epoch instead.
  • Loading branch information
gwynne committed Sep 8, 2021
1 parent f5f9378 commit 56a63b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/MySQLNIO/MySQLData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public struct MySQLData: CustomStringConvertible, ExpressibleByStringLiteral, Ex
case .bit:
return self.bool!.description
case .datetime, .timestamp:
return self.date!.description
return (self.time!.date ?? Date(timeIntervalSince1970: 0)).description
case .varchar, .varString, .string:
return self.string!.debugDescription
case .double:
Expand Down
7 changes: 7 additions & 0 deletions Tests/MySQLNIOTests/MySQLNIOTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ final class MySQLNIOTests: XCTestCase {
XCTAssert(time.microsecond == UInt32(100000))
XCTAssert(time2.microsecond == UInt32(100000))
}

func testDate_zeroIsInvalidButMySQLReturnsIt() throws {
let zeroTime = MySQLTime()
let data = MySQLData(time: zeroTime)

XCTAssertEqual(data.description, "1970-01-01 00:00:00 +0000")
}

func testString_lengthEncoded_uint8() throws {
let conn = try MySQLConnection.test(on: self.eventLoop).wait()
Expand Down

0 comments on commit 56a63b8

Please sign in to comment.