Skip to content

Commit

Permalink
Adding more tests for invalid dates
Browse files Browse the repository at this point in the history
  • Loading branch information
joakime committed Apr 23, 2024
1 parent 89f728c commit 20660bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.eclipse.jetty.http;

import java.nio.charset.StandardCharsets;
import java.time.DateTimeException;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
Expand Down Expand Up @@ -219,11 +220,18 @@ else if (token.length() == 4)
throw new IllegalArgumentException("Invalid [second]: " + datetime);

// RFC 6265 - Section 5.1.1 - Step 6
ZonedDateTime dateTime = ZonedDateTime.of(year,
month, day, hour, minute, second, 0, UTC);
try
{
ZonedDateTime dateTime = ZonedDateTime.of(year,
month, day, hour, minute, second, 0, UTC);

// RFC 6265 - Section 5.1.1 - Step 7
return dateTime;
// RFC 6265 - Section 5.1.1 - Step 7
return dateTime;
}
catch (DateTimeException e)
{
throw new IllegalArgumentException("Invalid date/time: " + datetime, e);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public static Stream<Arguments> dateTimeInvalid()

// - invalid day
args.add(Arguments.of("Tue, 00 Apr 2024 17:28:27 GMT", "Invalid [day]"));
args.add(Arguments.of("Tue, 31 Feb 2020 17:28:27 GMT", "Invalid date/time"));
// - long form month
args.add(Arguments.of("Wed, 22 August 1984 01:02:03 GMT", "Missing [month]"));
// - no day
Expand Down

0 comments on commit 20660bc

Please sign in to comment.