This repository was archived by the owner on Nov 20, 2018. It is now read-only.
File tree 2 files changed +13
-10
lines changed
src/Microsoft.AspNetCore.Http.Extensions
test/Microsoft.AspNetCore.Http.Extensions.Tests
2 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -195,17 +195,18 @@ public static string GetEncodedPathAndQuery(this HttpRequest request)
195
195
/// <returns></returns>
196
196
public static string GetDisplayUrl ( this HttpRequest request )
197
197
{
198
- var host = request . Host . Value ;
199
- var pathBase = request . PathBase . Value ;
200
- var path = request . Path . Value ;
201
- var queryString = request . QueryString . Value ;
198
+ var scheme = request . Scheme ?? string . Empty ;
199
+ var host = request . Host . Value ?? string . Empty ;
200
+ var pathBase = request . PathBase . Value ?? string . Empty ;
201
+ var path = request . Path . Value ?? string . Empty ;
202
+ var queryString = request . QueryString . Value ?? string . Empty ;
202
203
203
204
// PERF: Calculate string length to allocate correct buffer size for StringBuilder.
204
- var length = request . Scheme . Length + SchemeDelimiter . Length + host . Length
205
+ var length = scheme . Length + SchemeDelimiter . Length + host . Length
205
206
+ pathBase . Length + path . Length + queryString . Length ;
206
207
207
208
return new StringBuilder ( length )
208
- . Append ( request . Scheme )
209
+ . Append ( scheme )
209
210
. Append ( SchemeDelimiter )
210
211
. Append ( host )
211
212
. Append ( pathBase )
Original file line number Diff line number Diff line change @@ -55,17 +55,19 @@ public void GetEncodedUrlFromRequest()
55
55
Assert . Equal ( "http://my.xn--host-cpd:80/un%3Fescaped/base/un%3Fescaped?name=val%23ue" , request . GetEncodedUrl ( ) ) ;
56
56
}
57
57
58
- [ Fact ]
59
- public void GetDisplayUrlFromRequest ( )
58
+ [ Theory ]
59
+ [ InlineData ( "/un?escaped/base" ) ]
60
+ [ InlineData ( null ) ]
61
+ public void GetDisplayUrlFromRequest ( string pathBase )
60
62
{
61
63
var request = new DefaultHttpContext ( ) . Request ;
62
64
request . Scheme = "http" ;
63
65
request . Host = new HostString ( "my.HoΨst:80" ) ;
64
- request . PathBase = new PathString ( "/un?escaped/base" ) ;
66
+ request . PathBase = new PathString ( pathBase ) ;
65
67
request . Path = new PathString ( "/un?escaped" ) ;
66
68
request . QueryString = new QueryString ( "?name=val%23ue" ) ;
67
69
68
- Assert . Equal ( "http://my.hoψst:80/un?escaped/base /un?escaped?name=val%23ue" , request . GetDisplayUrl ( ) ) ;
70
+ Assert . Equal ( "http://my.hoψst:80" + pathBase + " /un?escaped?name=val%23ue", request . GetDisplayUrl ( ) ) ;
69
71
}
70
72
71
73
[ Theory ]
You can’t perform that action at this time.
0 commit comments