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

Make strptime() to check if date string is matching format completely. #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Piece.xs
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,12 @@ _strptime(pTHX_ const char *buf, const char *fmt, struct tm *tm, int *got_GMT)
*/
ptr = fmt;
while (*ptr != 0) {
if (*buf == 0)
break;
if (*buf == 0) {
/* trailing whitespace is allowed */
while (isspace((unsigned char)*ptr))
ptr++;
return (*ptr == 0) ? (char *)buf : 0;
}

c = *ptr++;

Expand Down
15 changes: 14 additions & 1 deletion t/02core.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Test::More tests => 96;
use Test::More tests => 98;

my $is_win32 = ($^O =~ /Win32/);
my $is_qnx = ($^O eq 'qnx');
Expand Down Expand Up @@ -227,3 +227,16 @@ cmp_ok(
951827696
);

eval { Time::Piece->strptime("2014", '%Y%m') };
like(
$@,
qr/Error parsing time/,
"croak if passed string wasn't enough to match with format"
);

eval { Time::Piece->strptime("", '%y') };
like(
$@,
qr/Error parsing time/,
"croak if empty string passed to strptime with non-empty format"
);