Removed the ? prefix from the QUERY_STRING server variable
This commit is contained in:
parent
2a153b38fe
commit
67c93a9acd
|
|
@ -7,7 +7,14 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.PatternSegments
|
||||||
{
|
{
|
||||||
public override string Evaluate(RewriteContext context, MatchResults ruleMatch, MatchResults condMatch)
|
public override string Evaluate(RewriteContext context, MatchResults ruleMatch, MatchResults condMatch)
|
||||||
{
|
{
|
||||||
return context.HttpContext.Request.QueryString.ToString();
|
var queryString = context.HttpContext.Request.QueryString.ToString();
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(queryString))
|
||||||
|
{
|
||||||
|
return queryString.Substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return queryString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Rewrite.Tests.UrlRewrite
|
||||||
[InlineData("HTTP_USER_AGENT", "useragent")]
|
[InlineData("HTTP_USER_AGENT", "useragent")]
|
||||||
[InlineData("HTTP_CONNECTION", "connection")]
|
[InlineData("HTTP_CONNECTION", "connection")]
|
||||||
[InlineData("HTTP_URL", "/foo")]
|
[InlineData("HTTP_URL", "/foo")]
|
||||||
[InlineData("QUERY_STRING", "?bar=1")]
|
[InlineData("QUERY_STRING", "bar=1")]
|
||||||
[InlineData("REQUEST_FILENAME", "/foo")]
|
[InlineData("REQUEST_FILENAME", "/foo")]
|
||||||
public void CheckServerVariableParsingAndApplication(string variable, string expected)
|
public void CheckServerVariableParsingAndApplication(string variable, string expected)
|
||||||
{
|
{
|
||||||
|
|
@ -61,5 +61,17 @@ namespace Microsoft.AspNetCore.Rewrite.Tests.UrlRewrite
|
||||||
var match = Regex.Match("foo/bar/baz", "(.*)/(.*)/(.*)");
|
var match = Regex.Match("foo/bar/baz", "(.*)/(.*)/(.*)");
|
||||||
return new MatchResults { BackReference = match.Groups, Success = match.Success };
|
return new MatchResults { BackReference = match.Groups, Success = match.Success };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
private void EmptyQueryStringCheck()
|
||||||
|
{
|
||||||
|
var context = new DefaultHttpContext();
|
||||||
|
var rewriteContext = new RewriteContext { HttpContext = context };
|
||||||
|
var testParserContext = new ParserContext("test");
|
||||||
|
var serverVar = ServerVariables.FindServerVariable("QUERY_STRING", testParserContext);
|
||||||
|
var lookup = serverVar.Evaluate(rewriteContext, CreateTestRuleMatch(), CreateTestCondMatch());
|
||||||
|
|
||||||
|
Assert.Equal(string.Empty, lookup);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,16 +12,13 @@ namespace Microsoft.AspNetCore.Rewrite.Tests.PatternSegments
|
||||||
[Fact]
|
[Fact]
|
||||||
public void QueryString_AssertSegmentIsCorrect()
|
public void QueryString_AssertSegmentIsCorrect()
|
||||||
{
|
{
|
||||||
// Arrange
|
|
||||||
var segement = new QueryStringSegment();
|
var segement = new QueryStringSegment();
|
||||||
var context = new RewriteContext { HttpContext = new DefaultHttpContext() };
|
var context = new RewriteContext { HttpContext = new DefaultHttpContext() };
|
||||||
context.HttpContext.Request.QueryString = new QueryString("?hey=1");
|
context.HttpContext.Request.QueryString = new QueryString("?hey=1");
|
||||||
|
|
||||||
// Act
|
|
||||||
var results = segement.Evaluate(context, null, null);
|
var results = segement.Evaluate(context, null, null);
|
||||||
|
|
||||||
// Assert
|
Assert.Equal("hey=1", results);
|
||||||
Assert.Equal("?hey=1", results);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue