Index: src/OFDate.m ================================================================== --- src/OFDate.m +++ src/OFDate.m @@ -268,17 +268,18 @@ format: (OFString*)format { self = [super init]; @try { + const char *UTF8String = [string UTF8String]; struct tm tm = { 0 }; int16_t tz = 0; tm.tm_isdst = -1; - if (of_strptime([string UTF8String], [format UTF8String], - &tm, &tz) == NULL) + if (of_strptime(UTF8String, [format UTF8String], + &tm, &tz) != UTF8String + [string UTF8StringLength]) @throw [OFInvalidFormatException exception]; _seconds = tmAndTzToTime(&tm, &tz); } @catch (id e) { [self release]; @@ -292,10 +293,11 @@ format: (OFString*)format { self = [super init]; @try { + const char *UTF8String = [string UTF8String]; struct tm tm = { 0 }; /* * of_strptime() can never set this to INT16_MAX, no matter * what is passed to it, so this is a safe way to figure out if * the date contains a time zone. @@ -302,12 +304,12 @@ */ int16_t tz = INT16_MAX; tm.tm_isdst = -1; - if (of_strptime([string UTF8String], [format UTF8String], - &tm, &tz) == NULL) + if (of_strptime(UTF8String, [format UTF8String], + &tm, &tz) != UTF8String + [string UTF8StringLength]) @throw [OFInvalidFormatException exception]; if (tz == INT16_MAX) { #ifndef OF_WINDOWS if ((_seconds = mktime(&tm)) == -1) Index: tests/OFDateTests.m ================================================================== --- tests/OFDateTests.m +++ tests/OFDateTests.m @@ -20,10 +20,12 @@ #import "OFDate.h" #import "OFString.h" #import "OFAutoreleasePool.h" +#import "OFInvalidFormatException.h" + #import "of_strptime.h" #import "TestsAppDelegate.h" static OFString *module = @"OFDate"; @@ -55,18 +57,28 @@ TEST(@"+[dateWithDateString:format:]", [[[OFDate dateWithDateString: @"2000-06-20T12:34:56+0200" format: @"%Y-%m-%dT%H:%M:%S%z"] description] isEqual: @"2000-06-20T10:34:56Z"]); + EXPECT_EXCEPTION(@"Detection of unparsed in " + @"+[dateWithDateString:format:]", OFInvalidFormatException, + [OFDate dateWithDateString: @"2000-06-20T12:34:56+0200x" + format: @"%Y-%m-%dT%H:%M:%S%z"]) + /* * We can only test local dates that specify a time zone, as the local * time zone differs between systems. */ TEST(@"+[dateWithLocalDateString:format:]", [[[OFDate dateWithLocalDateString: @"2000-06-20T12:34:56-0200" format: @"%Y-%m-%dT%H:%M:%S%z"] description] isEqual: @"2000-06-20T14:34:56Z"]); + + EXPECT_EXCEPTION(@"Detection of unparsed in " + @"+[dateWithLocalDateString:format:]", OFInvalidFormatException, + [OFDate dateWithLocalDateString: @"2000-06-20T12:34:56+0200x" + format: @"%Y-%m-%dT%H:%M:%S%z"]) TEST(@"-[isEqual:]", [d1 isEqual: [OFDate dateWithTimeIntervalSince1970: 0]] && ![d1 isEqual: [OFDate dateWithTimeIntervalSince1970: 0.0000001]])