Skip to content

Commit 7952a74

Browse files
committed
Reject inconsistent date strings
Check if the parsed date is bad by roundtripping to SystemTime. Release v1.0.1
1 parent 9fe1f17 commit 7952a74

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "httpdate"
3-
version = "1.0.0"
3+
version = "1.0.1"
44
authors = ["Pyfisch <[email protected]>"]
55
license = "MIT/Apache-2.0"
66
description = "HTTP date parsing and formatting"

src/date.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl HttpDate {
4141
&& self.mon <= 12
4242
&& self.year >= 1970
4343
&& self.year <= 9999
44+
&& &HttpDate::from(SystemTime::from(*self)) == self
4445
}
4546
}
4647

src/lib.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn fmt_http_date(d: SystemTime) -> String {
6363
#[cfg(test)]
6464
mod tests {
6565
use std::str;
66-
use std::time::{Duration, SystemTime, UNIX_EPOCH};
66+
use std::time::{Duration, UNIX_EPOCH};
6767

6868
use super::{fmt_http_date, parse_http_date, HttpDate};
6969

@@ -151,12 +151,9 @@ mod tests {
151151
}
152152

153153
#[test]
154-
fn test_date_equality() {
155-
let nov_07_sys = UNIX_EPOCH + Duration::new(784198117, 0);
156-
let nov_07 = nov_07_sys.into();
157-
let parsed = "Sun, 07 Nov 1994 08:48:37 GMT".parse::<HttpDate>().unwrap();
158-
let parsed_sys: SystemTime = parsed.into();
159-
assert_eq!(parsed_sys, nov_07_sys);
160-
assert_eq!(parsed, nov_07);
154+
fn test_parse_bad_date() {
155+
// 1994-11-07 is actually a Monday
156+
let parsed = "Sun, 07 Nov 1994 08:48:37 GMT".parse::<HttpDate>();
157+
assert!(parsed.is_err())
161158
}
162159
}

0 commit comments

Comments
 (0)