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

FixInvalidDayOffsetPreprocessor: Allow DURATION as value #182

Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ object FixInvalidDayOffsetPreprocessor : StreamPreprocessor() {
// Examples:
// TRIGGER:-P2DT
// TRIGGER:-PT2D
"^(DURATION|TRIGGER):-?P((T-?\\d+D)|(-?\\d+DT))\$",
// REFRESH-INTERVAL;VALUE=DURATION:PT1D
"(?:^|(DURATION|REFRESH-INTERVAL|RELATED-TO|TRIGGER);VALUE=)" +
rfc2822 marked this conversation as resolved.
Show resolved Hide resolved
"(DURATION|TRIGGER):-?P((T-?\\d+D)|(-?\\d+DT))$",
setOf(RegexOption.MULTILINE, RegexOption.IGNORE_CASE)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import java.time.Duration
import java.time.format.DateTimeParseException

class FixInvalidDayOffsetPreprocessorTest {

Expand All @@ -35,6 +36,22 @@ class FixInvalidDayOffsetPreprocessorTest {
)
}

@Test
fun test_FixString_SucceedsAsValueOnCorrectProperties() {
// By RFC 5545 the only properties allowed to hold DURATION as a VALUE are:
// DURATION, REFRESH, RELATED, TRIGGER
fixAndAssert("DURATION;VALUE=DURATION:P1D", "DURATION;VALUE=DURATION:PT1D")
fixAndAssert("REFRESH-INTERVAL;VALUE=DURATION:P1D", "REFRESH-INTERVAL;VALUE=DURATION:PT1D")
fixAndAssert("RELATED-TO;VALUE=DURATION:P1D", "RELATED-TO;VALUE=DURATION:PT1D")
fixAndAssert("TRIGGER;VALUE=DURATION:P1D", "TRIGGER;VALUE=DURATION:PT1D")
}

@Test(expected = DateTimeParseException::class)
fun test_FixString_FailsAsValueOnWrongProperty() {
// The update from RFC 2445 to RFC 5545 disallows using DURATION as a VALUE in FREEBUSY
fixAndAssert("FREEBUSY;VALUE=DURATION:P1D", "FREEBUSY;VALUE=DURATION:PT1D")
}

@Test
fun test_FixString_DayOffsetFrom_Invalid() {
fixAndAssert("DURATION:-P1D", "DURATION:-PT1D")
Expand Down
Loading