Fixed some bugs within the RouteMatcher to better support wild card and catch all matching. Added unit tests. Bumped package version to 1.2.9
This commit is contained in:
		@@ -22,12 +22,24 @@ namespace MontoyaTech.Rest.Net.Tests
 | 
				
			|||||||
            RouteMatcher.Matches("http://localhost/test1/test2", "/**", out _).Should().BeTrue();
 | 
					            RouteMatcher.Matches("http://localhost/test1/test2", "/**", out _).Should().BeTrue();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [Fact]
 | 
				
			||||||
 | 
					        public void SyntaxCatchAllEmptyShouldMatch()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            RouteMatcher.Matches("http://localhost/test1", "/test1/**", out _).Should().BeTrue();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
        public void SyntaxWithRootWildcardShouldMatch()
 | 
					        public void SyntaxWithRootWildcardShouldMatch()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            RouteMatcher.Matches("http://localhost/test1", "/*", out _).Should().BeTrue();
 | 
					            RouteMatcher.Matches("http://localhost/test1", "/*", out _).Should().BeTrue();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [Fact]
 | 
				
			||||||
 | 
					        public void SyntaxWildCardEmptyShouldMatch()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            RouteMatcher.Matches("http://localhost/test1", "/test1/*", out _).Should().BeTrue();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [Fact]
 | 
					        [Fact]
 | 
				
			||||||
        public void SyntaxWithRootWildcardShouldNotMatch()
 | 
					        public void SyntaxWithRootWildcardShouldNotMatch()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,7 @@
 | 
				
			|||||||
    <AssemblyName>MontoyaTech.Rest.Net</AssemblyName>
 | 
					    <AssemblyName>MontoyaTech.Rest.Net</AssemblyName>
 | 
				
			||||||
    <RootNamespace>MontoyaTech.Rest.Net</RootNamespace>
 | 
					    <RootNamespace>MontoyaTech.Rest.Net</RootNamespace>
 | 
				
			||||||
    <GenerateDocumentationFile>True</GenerateDocumentationFile>
 | 
					    <GenerateDocumentationFile>True</GenerateDocumentationFile>
 | 
				
			||||||
    <Version>1.2.8</Version>
 | 
					    <Version>1.2.9</Version>
 | 
				
			||||||
    <PackageReleaseNotes></PackageReleaseNotes>
 | 
					    <PackageReleaseNotes></PackageReleaseNotes>
 | 
				
			||||||
    <PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon>
 | 
					    <PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon>
 | 
				
			||||||
  </PropertyGroup>
 | 
					  </PropertyGroup>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,19 +72,30 @@ namespace MontoyaTech.Rest.Net
 | 
				
			|||||||
            int argumentIndex = 0;
 | 
					            int argumentIndex = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            //Check each segment against the url.
 | 
					            //Check each segment against the url.
 | 
				
			||||||
            var max = Math.Min(urlSegments.Length, syntaxSegments.Length);
 | 
					            int max = Math.Max(urlSegments.Length, syntaxSegments.Length);
 | 
				
			||||||
            for (int i = 0; i < max; i++)
 | 
					            for (int i = 0; i < max; i++)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                var syntaxSegment = syntaxSegments[i];
 | 
					                var syntaxSegment = i >= syntaxSegments.Length ? null : syntaxSegments[i];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                var urlSegment = urlSegments[i];
 | 
					                var urlSegment = i >= urlSegments.Length ? null : urlSegments[i];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                //If the syntax segment is null, this is not a match.
 | 
				
			||||||
 | 
					                if (syntaxSegment == null)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    return false;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
                //If the segments syntax is a double wild card then everything after this is a match.
 | 
					                //If the segments syntax is a double wild card then everything after this is a match.
 | 
				
			||||||
                if (syntaxSegment == "**")
 | 
					                else if (syntaxSegment == "**")
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    return true;
 | 
					                    return true;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                else
 | 
					                //If we ran out of url segments, and this syntax segment is a wild card, this is okay.
 | 
				
			||||||
 | 
					                else if (urlSegment == null && syntaxSegment == "*")
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    return true;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                //If we have a url segment see if it matches against the syntax segment.
 | 
				
			||||||
 | 
					                else if (urlSegment != null)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    var conditions = new List<string>();
 | 
					                    var conditions = new List<string>();
 | 
				
			||||||
                    var builder = new StringBuilder();
 | 
					                    var builder = new StringBuilder();
 | 
				
			||||||
@@ -145,11 +156,6 @@ namespace MontoyaTech.Rest.Net
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (urlSegments.Length > syntaxSegments.Length)
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            else if (syntaxSegments.Length > urlSegments.Length)
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user