diff --git a/Ical.Net/Constants.cs b/Ical.Net/Constants.cs index 59177c91..062b27e8 100644 --- a/Ical.Net/Constants.cs +++ b/Ical.Net/Constants.cs @@ -353,4 +353,19 @@ public static class CalendarMethods /// public const string DeclineCounter = "DECLINECOUNTER"; } + + /// + /// The defaults used for regular expressions. + /// + public static class RegexDefaults + { + /// + /// The default timeout for regular expressions in milliseconds. + /// + public const int TimeoutMilliseconds = 200; + /// + /// The default timeout for regular expressions. + /// + public static readonly TimeSpan Timeout = TimeSpan.FromMilliseconds(TimeoutMilliseconds); + } } \ No newline at end of file diff --git a/Ical.Net/Serialization/DataTypes/DateTimeSerializer.cs b/Ical.Net/Serialization/DataTypes/DateTimeSerializer.cs index 1e885e9c..f96fbbff 100644 --- a/Ical.Net/Serialization/DataTypes/DateTimeSerializer.cs +++ b/Ical.Net/Serialization/DataTypes/DateTimeSerializer.cs @@ -93,8 +93,8 @@ public override string SerializeToString(object obj) } private const RegexOptions _ciCompiled = RegexOptions.Compiled | RegexOptions.IgnoreCase; - internal static readonly Regex DateOnlyMatch = new Regex(@"^((\d{4})(\d{2})(\d{2}))?$", _ciCompiled); - internal static readonly Regex FullDateTimePatternMatch = new Regex(@"^((\d{4})(\d{2})(\d{2}))T((\d{2})(\d{2})(\d{2})(Z)?)$", _ciCompiled); + internal static readonly Regex DateOnlyMatch = new Regex(@"^((\d{4})(\d{2})(\d{2}))?$", _ciCompiled, RegexDefaults.Timeout); + internal static readonly Regex FullDateTimePatternMatch = new Regex(@"^((\d{4})(\d{2})(\d{2}))T((\d{2})(\d{2})(\d{2})(Z)?)$", _ciCompiled, RegexDefaults.Timeout); public override object Deserialize(TextReader tr) { diff --git a/Ical.Net/Serialization/DataTypes/RecurrencePatternSerializer.cs b/Ical.Net/Serialization/DataTypes/RecurrencePatternSerializer.cs index 3bfd99fd..3d11fea0 100644 --- a/Ical.Net/Serialization/DataTypes/RecurrencePatternSerializer.cs +++ b/Ical.Net/Serialization/DataTypes/RecurrencePatternSerializer.cs @@ -190,25 +190,25 @@ public override string SerializeToString(object obj) private const RegexOptions _ciCompiled = RegexOptions.IgnoreCase | RegexOptions.Compiled; internal static readonly Regex OtherInterval = - new Regex(@"every\s+(?other|\d+)?\w{0,2}\s*(?second|minute|hour|day|week|month|year)s?,?\s*(?.+)", _ciCompiled); + new Regex(@"every\s+(?other|\d+)?\w{0,2}\s*(?second|minute|hour|day|week|month|year)s?,?\s*(?.+)", _ciCompiled, RegexDefaults.Timeout); - internal static readonly Regex AdverbFrequencies = new Regex(@"FREQ=(SECONDLY|MINUTELY|HOURLY|DAILY|WEEKLY|MONTHLY|YEARLY);?(.*)", _ciCompiled); + internal static readonly Regex AdverbFrequencies = new Regex(@"FREQ=(SECONDLY|MINUTELY|HOURLY|DAILY|WEEKLY|MONTHLY|YEARLY);?(.*)", _ciCompiled, RegexDefaults.Timeout); - internal static readonly Regex NumericTemporalUnits = new Regex(@"(?\d+)\w\w\s+(?second|minute|hour|day|week|month)", _ciCompiled); + internal static readonly Regex NumericTemporalUnits = new Regex(@"(?\d+)\w\w\s+(?second|minute|hour|day|week|month)", _ciCompiled, RegexDefaults.Timeout); - internal static readonly Regex TemporalUnitType = new Regex(@"(?second|minute|hour|day|week|month)\s+(?\d+)", _ciCompiled); + internal static readonly Regex TemporalUnitType = new Regex(@"(?second|minute|hour|day|week|month)\s+(?\d+)", _ciCompiled, RegexDefaults.Timeout); internal static readonly Regex RelativeDaysOfWeek = new Regex( @"(?\d+\w{0,2})?(\w|\s)+?(?first)?(?last)?\s*((?sunday|monday|tuesday|wednesday|thursday|friday|saturday)\s*(and|or)?\s*)+", - _ciCompiled); + _ciCompiled, RegexDefaults.Timeout); internal static readonly Regex Time = new Regex(@"at\s+(?\d{1,2})(:(?\d{2})((:|\.)(?\d{2}))?)?\s*(?(a|p)m?)?", - _ciCompiled); + _ciCompiled, RegexDefaults.Timeout); - internal static readonly Regex RecurUntil = new Regex(@"^\s*until\s+(?.+)$", _ciCompiled); + internal static readonly Regex RecurUntil = new Regex(@"^\s*until\s+(?.+)$", _ciCompiled, RegexDefaults.Timeout); - internal static readonly Regex SpecificRecurrenceCount = new Regex(@"^\s*for\s+(?\d+)\s+occurrences\s*$", _ciCompiled); + internal static readonly Regex SpecificRecurrenceCount = new Regex(@"^\s*for\s+(?\d+)\s+occurrences\s*$", _ciCompiled, RegexDefaults.Timeout); public override object Deserialize(TextReader tr) { diff --git a/Ical.Net/Serialization/DataTypes/RequestStatusSerializer.cs b/Ical.Net/Serialization/DataTypes/RequestStatusSerializer.cs index c4b13273..f192884a 100644 --- a/Ical.Net/Serialization/DataTypes/RequestStatusSerializer.cs +++ b/Ical.Net/Serialization/DataTypes/RequestStatusSerializer.cs @@ -59,8 +59,8 @@ public override string SerializeToString(object obj) } } - internal static readonly Regex NarrowRequestMatch = new Regex(@"(.*?[^\\]);(.*?[^\\]);(.+)", RegexOptions.Compiled); - internal static readonly Regex BroadRequestMatch = new Regex(@"(.*?[^\\]);(.+)", RegexOptions.Compiled); + internal static readonly Regex NarrowRequestMatch = new Regex(@"(.*?[^\\]);(.*?[^\\]);(.+)", RegexOptions.Compiled, RegexDefaults.Timeout); + internal static readonly Regex BroadRequestMatch = new Regex(@"(.*?[^\\]);(.+)", RegexOptions.Compiled, RegexDefaults.Timeout); public override object Deserialize(TextReader tr) { diff --git a/Ical.Net/Serialization/DataTypes/StatusCodeSerializer.cs b/Ical.Net/Serialization/DataTypes/StatusCodeSerializer.cs index 404bcc1d..5e93808d 100644 --- a/Ical.Net/Serialization/DataTypes/StatusCodeSerializer.cs +++ b/Ical.Net/Serialization/DataTypes/StatusCodeSerializer.cs @@ -29,7 +29,7 @@ public override string SerializeToString(object obj) return Encode(sc, Escape(string.Join(".", vals))); } - internal static readonly Regex StatusCode = new Regex(@"\d(\.\d+)*", RegexOptions.Compiled | RegexOptions.CultureInvariant); + internal static readonly Regex StatusCode = new Regex(@"\d(\.\d+)*", RegexOptions.Compiled | RegexOptions.CultureInvariant, RegexDefaults.Timeout); public override object Deserialize(TextReader tr) { diff --git a/Ical.Net/Serialization/DataTypes/StringSerializer.cs b/Ical.Net/Serialization/DataTypes/StringSerializer.cs index 42dc1dff..e54946cb 100644 --- a/Ical.Net/Serialization/DataTypes/StringSerializer.cs +++ b/Ical.Net/Serialization/DataTypes/StringSerializer.cs @@ -14,7 +14,7 @@ public StringSerializer() { } public StringSerializer(SerializationContext ctx) : base(ctx) { } - internal static readonly Regex SingleBackslashMatch = new Regex(@"(?\+|-)?P(((?\d+)W)|(?
((?\d+)D)?(?