Skip to content

Commit

Permalink
fix: greedy variable can be any value
Browse files Browse the repository at this point in the history
  • Loading branch information
philasmar committed Dec 19, 2024
1 parent 8b90fa5 commit 87a8dcf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,20 @@ private bool IsRouteConfigValid(ApiGatewayRouteConfig routeConfig)
return false;
}

var occurrences = routeConfig.Path.Split("{proxy+}").Length - 1;
if (occurrences > 1)
var occurrences = routeConfig.Path
.Split('/')
.Where(
x => x.StartsWith("{") &&
x.EndsWith("+}"))
.ToList();
if (occurrences.Count > 1)
{
_logger.LogError("The route config {Method} {Path} cannot have multiple greedy variables {{proxy+}}.",
routeConfig.HttpMethod, routeConfig.Path);
return false;
}

if (occurrences == 1 && !routeConfig.Path.EndsWith("/{proxy+}"))
if (occurrences.Count == 1 && !routeConfig.Path.EndsWith($"/{occurrences.Last()}"))
{
_logger.LogError("The route config {Method} {Path} uses a greedy variable {{proxy+}} but does not end with it.",
routeConfig.HttpMethod, routeConfig.Path);
Expand Down Expand Up @@ -412,7 +417,7 @@ private bool IsVariableSegment(string segment)
/// <returns><c>true</c> if the segment is a greedy variable segment; <c>false</c> otherwise.</returns>
private bool IsGreedyVariable(string segment)
{
return segment.Equals("{proxy+}", StringComparison.InvariantCultureIgnoreCase);
return segment.StartsWith("{") && segment.EndsWith("+}");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ public void Constructor_LoadsAndParsesListOfConfigs()
Assert.Equal("Function2", result2.LambdaResourceName);
}

[Fact]
public void CatchAllRouteConfig()
[Theory]
[InlineData("proxy")]
[InlineData("anyvalue")]
public void CatchAllRouteConfig(string variableName)
{
// Arange
var routeConfigs = new List<ApiGatewayRouteConfig>
Expand All @@ -169,7 +171,7 @@ public void CatchAllRouteConfig()
{
LambdaResourceName = "F1",
HttpMethod = "ANY",
Path = "/{proxy+}"
Path = $"/{{{variableName}+}}"
}
};

Expand Down

0 comments on commit 87a8dcf

Please sign in to comment.