diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-01-23 00:31:26 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-01-23 00:31:26 -0500 |
commit | d1935e686c6396519a1ff9b1b429cd55adcf8d11 (patch) | |
tree | 3fe7770e4ee13c8fe4d7a25eb041210b42e7b9b6 /src/SMAPI.Web/Framework/VersionConstraint.cs | |
parent | 381de5eba9f9822c3483abdf64396cec794e3d03 (diff) | |
download | SMAPI-d1935e686c6396519a1ff9b1b429cd55adcf8d11.tar.gz SMAPI-d1935e686c6396519a1ff9b1b429cd55adcf8d11.tar.bz2 SMAPI-d1935e686c6396519a1ff9b1b429cd55adcf8d11.zip |
add full internal support for non-standard four-part versions
Diffstat (limited to 'src/SMAPI.Web/Framework/VersionConstraint.cs')
-rw-r--r-- | src/SMAPI.Web/Framework/VersionConstraint.cs | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/SMAPI.Web/Framework/VersionConstraint.cs b/src/SMAPI.Web/Framework/VersionConstraint.cs index 2d6ec603..72f5ef84 100644 --- a/src/SMAPI.Web/Framework/VersionConstraint.cs +++ b/src/SMAPI.Web/Framework/VersionConstraint.cs @@ -1,16 +1,34 @@ -using Microsoft.AspNetCore.Routing.Constraints; +using System; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Routing; using StardewModdingAPI.Toolkit; namespace StardewModdingAPI.Web.Framework { /// <summary>Constrains a route value to a valid semantic version.</summary> - internal class VersionConstraint : RegexRouteConstraint + internal class VersionConstraint : IRouteConstraint { /********* ** Public methods *********/ - /// <summary>Construct an instance.</summary> - public VersionConstraint() - : base(SemanticVersion.Regex) { } + /// <summary>Get whether the URL parameter contains a valid value for this constraint.</summary> + /// <param name="httpContext">An object that encapsulates information about the HTTP request.</param> + /// <param name="route">The router that this constraint belongs to.</param> + /// <param name="routeKey">The name of the parameter that is being checked.</param> + /// <param name="values">A dictionary that contains the parameters for the URL.</param> + /// <param name="routeDirection">An object that indicates whether the constraint check is being performed when an incoming request is being handled or when a URL is being generated.</param> + /// <returns><c>true</c> if the URL parameter contains a valid value; otherwise, <c>false</c>.</returns> + public bool Match(HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection) + { + if (routeKey == null) + throw new ArgumentNullException(nameof(routeKey)); + if (values == null) + throw new ArgumentNullException(nameof(values)); + + return + values.TryGetValue(routeKey, out object routeValue) + && routeValue is string routeStr + && SemanticVersion.TryParseNonStandard(routeStr, out _); + } } } |