mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 10:35:28 +08:00 
			
		
		
		
	This commit is contained in:
		
				
					committed by
					
						
						Tom Pallister
					
				
			
			
				
	
			
			
			
						parent
						
							b60d26e1c6
						
					
				
				
					commit
					9db4273f18
				
			@@ -6,7 +6,7 @@ namespace Ocelot.Configuration.Creator
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    public class UpstreamTemplatePatternCreator : IUpstreamTemplatePatternCreator
 | 
					    public class UpstreamTemplatePatternCreator : IUpstreamTemplatePatternCreator
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private const string RegExMatchEverything = "[0-9a-zA-Z].*";
 | 
					        private const string RegExMatchOneOrMoreOfEverything = ".+";
 | 
				
			||||||
        private const string RegExMatchEndString = "$";
 | 
					        private const string RegExMatchEndString = "$";
 | 
				
			||||||
        private const string RegExIgnoreCase = "(?i)";
 | 
					        private const string RegExIgnoreCase = "(?i)";
 | 
				
			||||||
        private const string RegExForwardSlashOnly = "^/$";
 | 
					        private const string RegExForwardSlashOnly = "^/$";
 | 
				
			||||||
@@ -37,7 +37,7 @@ namespace Ocelot.Configuration.Creator
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            foreach (var placeholder in placeholders)
 | 
					            foreach (var placeholder in placeholders)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                upstreamTemplate = upstreamTemplate.Replace(placeholder, RegExMatchEverything);
 | 
					                upstreamTemplate = upstreamTemplate.Replace(placeholder, RegExMatchOneOrMoreOfEverything);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (upstreamTemplate == "/")
 | 
					            if (upstreamTemplate == "/")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,3 @@
 | 
				
			|||||||
using System;
 | 
					 | 
				
			||||||
using Ocelot.Configuration.Creator;
 | 
					using Ocelot.Configuration.Creator;
 | 
				
			||||||
using Ocelot.Configuration.File;
 | 
					using Ocelot.Configuration.File;
 | 
				
			||||||
using Ocelot.Values;
 | 
					using Ocelot.Values;
 | 
				
			||||||
@@ -30,7 +29,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
 | 
					            this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
 | 
				
			||||||
                .When(x => x.WhenICreateTheTemplatePattern())
 | 
					                .When(x => x.WhenICreateTheTemplatePattern())
 | 
				
			||||||
                .Then(x => x.ThenTheFollowingIsReturned("^(?i)/orders/[0-9a-zA-Z].*$"))
 | 
					                .Then(x => x.ThenTheFollowingIsReturned("^(?i)/orders/.+$"))
 | 
				
			||||||
                .And(x => ThenThePriorityIs(0))
 | 
					                .And(x => ThenThePriorityIs(0))
 | 
				
			||||||
                .BDDfy();
 | 
					                .BDDfy();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -62,7 +61,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
 | 
					            this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
 | 
				
			||||||
                .When(x => x.WhenICreateTheTemplatePattern())
 | 
					                .When(x => x.WhenICreateTheTemplatePattern())
 | 
				
			||||||
                .Then(x => x.ThenTheFollowingIsReturned("^(?i)/PRODUCTS/[0-9a-zA-Z].*$"))
 | 
					                .Then(x => x.ThenTheFollowingIsReturned("^(?i)/PRODUCTS/.+$"))
 | 
				
			||||||
                .And(x => ThenThePriorityIs(1))
 | 
					                .And(x => ThenThePriorityIs(1))
 | 
				
			||||||
                .BDDfy();
 | 
					                .BDDfy();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -93,7 +92,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
				
			|||||||
                };
 | 
					                };
 | 
				
			||||||
            this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
 | 
					            this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
 | 
				
			||||||
                .When(x => x.WhenICreateTheTemplatePattern())
 | 
					                .When(x => x.WhenICreateTheTemplatePattern())
 | 
				
			||||||
                .Then(x => x.ThenTheFollowingIsReturned("^/PRODUCTS/[0-9a-zA-Z].*$"))
 | 
					                .Then(x => x.ThenTheFollowingIsReturned("^/PRODUCTS/.+$"))
 | 
				
			||||||
                .And(x => ThenThePriorityIs(1))
 | 
					                .And(x => ThenThePriorityIs(1))
 | 
				
			||||||
                .BDDfy();
 | 
					                .BDDfy();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -109,7 +108,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
 | 
					            this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
 | 
				
			||||||
                .When(x => x.WhenICreateTheTemplatePattern())
 | 
					                .When(x => x.WhenICreateTheTemplatePattern())
 | 
				
			||||||
                .Then(x => x.ThenTheFollowingIsReturned("^/api/products/[0-9a-zA-Z].*$"))
 | 
					                .Then(x => x.ThenTheFollowingIsReturned("^/api/products/.+$"))
 | 
				
			||||||
                .And(x => ThenThePriorityIs(1))
 | 
					                .And(x => ThenThePriorityIs(1))
 | 
				
			||||||
                .BDDfy();
 | 
					                .BDDfy();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -125,7 +124,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
 | 
					            this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
 | 
				
			||||||
                .When(x => x.WhenICreateTheTemplatePattern())
 | 
					                .When(x => x.WhenICreateTheTemplatePattern())
 | 
				
			||||||
                .Then(x => x.ThenTheFollowingIsReturned("^/api/products/[0-9a-zA-Z].*/variants/[0-9a-zA-Z].*$"))
 | 
					                .Then(x => x.ThenTheFollowingIsReturned("^/api/products/.+/variants/.+$"))
 | 
				
			||||||
                .And(x => ThenThePriorityIs(1))
 | 
					                .And(x => ThenThePriorityIs(1))
 | 
				
			||||||
                .BDDfy();
 | 
					                .BDDfy();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -141,7 +140,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
 | 
					            this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
 | 
				
			||||||
                .When(x => x.WhenICreateTheTemplatePattern())
 | 
					                .When(x => x.WhenICreateTheTemplatePattern())
 | 
				
			||||||
                .Then(x => x.ThenTheFollowingIsReturned("^/api/products/[0-9a-zA-Z].*/variants/[0-9a-zA-Z].*(/|)$"))
 | 
					                .Then(x => x.ThenTheFollowingIsReturned("^/api/products/.+/variants/.+(/|)$"))
 | 
				
			||||||
                .And(x => ThenThePriorityIs(1))
 | 
					                .And(x => ThenThePriorityIs(1))
 | 
				
			||||||
                .BDDfy();
 | 
					                .BDDfy();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -187,7 +186,7 @@ namespace Ocelot.UnitTests.Configuration
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
 | 
					            this.Given(x => x.GivenTheFollowingFileReRoute(fileReRoute))
 | 
				
			||||||
                .When(x => x.WhenICreateTheTemplatePattern())
 | 
					                .When(x => x.WhenICreateTheTemplatePattern())
 | 
				
			||||||
                .Then(x => x.ThenTheFollowingIsReturned("^/[0-9a-zA-Z].*/products/variants/[0-9a-zA-Z].*(/|)$"))
 | 
					                .Then(x => x.ThenTheFollowingIsReturned("^/.+/products/variants/.+(/|)$"))
 | 
				
			||||||
                .And(x => ThenThePriorityIs(1))
 | 
					                .And(x => ThenThePriorityIs(1))
 | 
				
			||||||
                .BDDfy();
 | 
					                .BDDfy();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user