Skip to content

Commit

Permalink
Single Quote Trimming in Routes (Azure#1722)
Browse files Browse the repository at this point in the history
Bug Fix: 
1. Correct the parsing mechanism for the use of `'` in a route `BrokeredEndpoint()`
2. Add a unit test to verify the parsing of `'` in a route `BrokeredEndpoint()`
  • Loading branch information
yophilav authored Sep 19, 2019
1 parent db0afce commit a68c64f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public override void ExitSystemEndpoint(RouteParser.SystemEndpointContext contex
public override void ExitFuncEndpoint(RouteParser.FuncEndpointContext context)
{
string funcName = context.func.Text;
string address = context.endpoint.Text.Trim('"');
string address = context.endpoint.Text.Substring(1, context.endpoint.Text.Length - 2);
Endpoint endpoint = this.endpointFactory.CreateFunctionEndpoint(funcName, address);
this.Endpoint = endpoint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class RouteFactoryTest
[Theory]
public void TestParseRouteWithFunctionEndpoint(string routeString, IMessageSource expectedSource, string expectedCondition, string function, string inputEndpoint)
{
var mockEndpointFactory = new Mock<IEndpointFactory>();
var mockEndpointFactory = new Mock<IEndpointFactory>(MockBehavior.Strict);
mockEndpointFactory.Setup(
ef => ef.CreateFunctionEndpoint(
It.Is<string>(s => s.Equals(function, StringComparison.OrdinalIgnoreCase)),
Expand All @@ -41,7 +41,7 @@ public void TestParseRouteWithFunctionEndpoint(string routeString, IMessageSourc
[Theory]
public void TestParseRouteWithSystemEndpoint(string routeString, IMessageSource expectedSource, string expectedCondition, string systemEndpoint)
{
var mockEndpointFactory = new Mock<IEndpointFactory>();
var mockEndpointFactory = new Mock<IEndpointFactory>(MockBehavior.Strict);
mockEndpointFactory.Setup(
ef => ef.CreateSystemEndpoint(
It.Is<string>(s => s.Equals(systemEndpoint, StringComparison.OrdinalIgnoreCase))))
Expand All @@ -64,6 +64,12 @@ public void TestParseRouteWithSystemEndpoint(string routeString, IMessageSource
[InlineData(@"FORM /messages/modules/adapter INTO brokeredEndpoint(""/modules/alertLogic/inputs/in"")")]
[InlineData(@"SELECT FROM /messages/modules/adapter INTO brokeredEndpoint(""/modules/alertLogic/inputs/in"")")]
[InlineData(@"FROM INTO brokeredEndpoint(""/modules/alertLogic/inputs/in"")")]
[InlineData(@"FROM /* INTO brokeredEndpoint(""/modules/alertLogic/inputs/in')")]
[InlineData(@"FROM /* INTO brokeredEndpoint('/modules/alertLogic/inputs/in"")")]
[InlineData(@"FROM /* INTO brokeredEndpoint(""""/modules/alertLogic/inputs/in"""")")]
[InlineData(@"FROM /* INTO brokeredEndpoint(''/modules/alertLogic/inputs/in'')")]
[InlineData(@"FROM /* INTO brokeredEndpoint('""/modules/alertLogic/inputs/in'"")")]
[InlineData(@"FROM /* INTO brokeredEndpoint(""'/modules/alertLogic/inputs/in""')")]
[InlineData(@"FROM /messages WHERE temp == 100 INTO brokeredEndpoint(""/modules/alertLogic/inputs/in"")")]
[InlineData(@"FROM /messages WHERE INTO brokeredEndpoint(""/modules/alertLogic/inputs/in"")")]
[InlineData(@"FROM /messages WHERE temp = 'high' INTO")]
Expand All @@ -87,6 +93,7 @@ public void TestInvalidRoutes(string routeString)
public static IEnumerable<object[]> GetFunctionEndpointParserData()
{
var testData = new List<object[]>();

testData.Add(
new object[]
{
Expand All @@ -97,6 +104,36 @@ public static IEnumerable<object[]> GetFunctionEndpointParserData()
"/modules/alertLogic/inputs/in"
});

testData.Add(
new object[]
{
@"FROM /* INTO brokeredEndpoint('/modules/alertLogic/inputs/in')",
CustomMessageSource.Create("/"),
"true",
"brokeredEndpoint",
"/modules/alertLogic/inputs/in"
});

testData.Add(
new object[]
{
@"FROM /* INTO brokeredEndpoint('/modules/alert""Logic/inputs/in')",
CustomMessageSource.Create("/"),
"true",
"brokeredEndpoint",
@"/modules/alert""Logic/inputs/in"
});

testData.Add(
new object[]
{
@"FROM /* INTO brokeredEndpoint(""/modules/alert'Logic/inputs/in"")",
CustomMessageSource.Create("/"),
"true",
"brokeredEndpoint",
"/modules/alert'Logic/inputs/in"
});

testData.Add(
new object[]
{
Expand Down

0 comments on commit a68c64f

Please sign in to comment.