-
-
Notifications
You must be signed in to change notification settings - Fork 168
236 - Implement EntityDescriptor attribute 'cacheDuration' as a 'Duration Period' #255
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |||||||||
| using System.Security.Cryptography.X509Certificates; | ||||||||||
| using System.Xml; | ||||||||||
| using System.Xml.Linq; | ||||||||||
| using System.Text.RegularExpressions; | ||||||||||
| #if NETFULL | ||||||||||
| using System.IdentityModel.Tokens; | ||||||||||
| #else | ||||||||||
|
|
@@ -49,6 +50,30 @@ public string IdAsString | |||||||||
| /// </summary> | ||||||||||
| public int? ValidUntil { get; set; } | ||||||||||
|
|
||||||||||
| /// <summary> | ||||||||||
| /// [Optional] | ||||||||||
| /// Optional attribute indicates how long a metadata consumer should cache this metadata before attempting to re-fetch. | ||||||||||
| /// Value must be an XML Schema duration (https://www.w3.org/TR/xmlschema-2/#duration). Example: P1D, PT12H, P2Y3M. | ||||||||||
| /// Regex used for validation: ^-?P(\d*Y)?(\d*M)?(\d*D)?(T(\d*H)?(\d*M)?(\d*S)?)?$ | ||||||||||
| /// Throws <see cref="ArgumentException"/> if set to a non-empty value that does not match the duration pattern. | ||||||||||
| /// </summary> | ||||||||||
| public string CacheDuration | ||||||||||
| { | ||||||||||
| get => _cacheDuration; | ||||||||||
| set | ||||||||||
| { | ||||||||||
| if(!string.IsNullOrEmpty(value) && !CacheDurationRegex.IsMatch(value)) | ||||||||||
| { | ||||||||||
| throw new ArgumentException($"Invalid cacheDuration format. See https://www.w3.org/TR/xmlschema-2/#duration. Value: '{value}'"); | ||||||||||
| } | ||||||||||
| _cacheDuration = value; | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private string _cacheDuration; | ||||||||||
| // Require at least one date or time component after 'P' using a lookahead. See https://www.w3.org/TR/xmlschema-2/#duration | ||||||||||
| private static readonly Regex CacheDurationRegex = new Regex(@"^-?P(?=\d|T)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$", RegexOptions.Compiled); | ||||||||||
|
Comment on lines
+74
to
+75
|
||||||||||
| // Require at least one date or time component after 'P' using a lookahead. See https://www.w3.org/TR/xmlschema-2/#duration | |
| private static readonly Regex CacheDurationRegex = new Regex(@"^-?P(?=\d|T)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$", RegexOptions.Compiled); | |
| // Require at least one date or time component after 'P' using a lookahead. See https://www.w3.org/TR/xmlschema-2/#duration | |
| private static readonly Regex CacheDurationRegex = new Regex(@"^-?P(?=\d|T)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$", RegexOptions.Compiled); |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |||||||||
| using System.Threading.Tasks; | ||||||||||
| using System.Xml; | ||||||||||
| using System.Xml.Linq; | ||||||||||
| using System.Text.RegularExpressions; | ||||||||||
| #if NETFULL | ||||||||||
| using System.IdentityModel.Tokens; | ||||||||||
| #else | ||||||||||
|
|
@@ -53,6 +54,30 @@ public string IdAsString | |||||||||
| /// </summary> | ||||||||||
| public int? ValidUntil { get; set; } | ||||||||||
|
|
||||||||||
| /// <summary> | ||||||||||
| /// [Optional] | ||||||||||
| /// Optional attribute indicates how long a metadata consumer should cache this metadata before attempting to re-fetch. | ||||||||||
| /// Value must be an XML Schema duration (https://www.w3.org/TR/xmlschema-2/#duration). Example: P1D, PT12H, P2Y3M. | ||||||||||
| /// Regex used for validation: ^-?P(\d*Y)?(\d*M)?(\d*D)?(T(\d*H)?(\d*M)?(\d*S)?)?$ | ||||||||||
|
||||||||||
| /// Regex used for validation: ^-?P(\d*Y)?(\d*M)?(\d*D)?(T(\d*H)?(\d*M)?(\d*S)?)?$ | |
| /// Regex used for validation: ^-?P(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$ |
Copilot
AI
Sep 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment and regex are placed between the private field declaration and the next property. This breaks the logical grouping of the CacheDuration property members. Move the regex and its comment to immediately follow the private field declaration at line 77.
| // Require at least one date or time component after 'P' using a lookahead. See https://www.w3.org/TR/xmlschema-2/#duration | |
| private static readonly Regex CacheDurationRegex = new Regex(@"^-?P(?=\d|T)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$", RegexOptions.Compiled); | |
| // Require at least one date or time component after 'P' using a lookahead. See https://www.w3.org/TR/xmlschema-2/#duration | |
| private static readonly Regex CacheDurationRegex = new Regex(@"^-?P(?=\d|T)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$", RegexOptions.Compiled); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern in the documentation (line 57) does not match the actual regex implementation. The documentation shows
(\d*Y)?(\d*M)?(\d*D)?but the implementation uses(\d+Y)?(\d+M)?(\d+W)?(\d+D)?with\d+instead of\d*and includes(\d+W)?for weeks.