fix duplicate semver regex

This commit is contained in:
Jesse Plamondon-Willard 2017-10-08 00:11:50 -04:00
parent 51f5be1e74
commit 24428d4405
2 changed files with 11 additions and 15 deletions

View File

@ -8,20 +8,6 @@ namespace StardewModdingAPI.Common
/// <remarks>The implementation is defined by Semantic Version 2.0 (http://semver.org/).</remarks> /// <remarks>The implementation is defined by Semantic Version 2.0 (http://semver.org/).</remarks>
internal class SemanticVersionImpl internal class SemanticVersionImpl
{ {
/*********
** Properties
*********/
/// <summary>A regular expression matching a semantic version string.</summary>
/// <remarks>
/// This pattern is derived from the BNF documentation in the <a href="https://github.com/mojombo/semver">semver repo</a>,
/// with three important deviations intended to support Stardew Valley mod conventions:
/// - allows short-form "x.y" versions;
/// - allows hyphens in prerelease tags as synonyms for dots (like "-unofficial-update.3");
/// - doesn't allow '+build' suffixes.
/// </remarks>
private static readonly Regex Regex = new Regex(@"^(?>(?<major>0|[1-9]\d*))\.(?>(?<minor>0|[1-9]\d*))(?>(?:\.(?<patch>0|[1-9]\d*))?)(?:-(?<prerelease>(?>[a-z0-9]+[\-\.]?)+))?$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.ExplicitCapture);
/********* /*********
** Accessors ** Accessors
*********/ *********/
@ -37,6 +23,15 @@ namespace StardewModdingAPI.Common
/// <summary>An optional prerelease tag.</summary> /// <summary>An optional prerelease tag.</summary>
public string Tag { get; } public string Tag { get; }
/// <summary>A regular expression matching a semantic version string.</summary>
/// <remarks>
/// This pattern is derived from the BNF documentation in the <a href="https://github.com/mojombo/semver">semver repo</a>,
/// with three important deviations intended to support Stardew Valley mod conventions:
/// - allows short-form "x.y" versions;
/// - allows hyphens in prerelease tags as synonyms for dots (like "-unofficial-update.3");
/// - doesn't allow '+build' suffixes.
/// </remarks>
internal static readonly Regex Regex = new Regex(@"^(?>(?<major>0|[1-9]\d*))\.(?>(?<minor>0|[1-9]\d*))(?>(?:\.(?<patch>0|[1-9]\d*))?)(?:-(?<prerelease>(?>[a-z0-9]+[\-\.]?)+))?$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.ExplicitCapture);
/********* /*********
** Public methods ** Public methods

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Routing.Constraints; using Microsoft.AspNetCore.Routing.Constraints;
using StardewModdingAPI.Common;
namespace StardewModdingAPI.Web.Framework namespace StardewModdingAPI.Web.Framework
{ {
@ -10,6 +11,6 @@ namespace StardewModdingAPI.Web.Framework
*********/ *********/
/// <summary>Construct an instance.</summary> /// <summary>Construct an instance.</summary>
public VersionConstraint() public VersionConstraint()
: base(@"^v(?>(?<major>0|[1-9]\d*))\.(?>(?<minor>0|[1-9]\d*))(?>(?:\.(?<patch>0|[1-9]\d*))?)(?:-(?<prerelease>(?>[a-z0-9]+[\-\.]?)+))?$") { } : base(SemanticVersionImpl.Regex) { }
} }
} }