Added ToEscapeString() and ToEscapeDataString() (#11)
* Added ToEscapeString() and ToEscapeDataString(), added desciption in readme, and added unit tests * added changes from PR feedback
This commit is contained in:
committed by
Tommy Parnell
parent
be92d91ef6
commit
9b1d037a88
@@ -141,5 +141,21 @@ namespace FluentUriBuilder.Tests
|
||||
.WithParameter(dictionary);
|
||||
Assert.Equal("http://awesome.com/?yo=dawg&troll=toll&hammer", url.Uri.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestToEscapedString()
|
||||
{
|
||||
var url = new UriBuilder("http://awesome.com")
|
||||
.WithParameter("yo","dawg<");
|
||||
Assert.Equal("http://awesome.com/?yo=dawg%3C", url.ToEscapeString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestToEscapedDataString()
|
||||
{
|
||||
var url = new UriBuilder("http://awesome.com")
|
||||
.WithParameter("yo","dawg<");
|
||||
Assert.Equal("http%3A%2F%2Fawesome.com%2F%3Fyo%3Ddawg%3C", url.ToEscapeDataString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,10 +127,7 @@ namespace System
|
||||
return bld;
|
||||
}
|
||||
|
||||
public static string PathAndQuery(this UriBuilder bld)
|
||||
{
|
||||
return bld.Path + bld.Query;
|
||||
}
|
||||
public static string PathAndQuery(this UriBuilder bld) => (bld.Path + bld.Query);
|
||||
|
||||
/// <summary>
|
||||
/// Use Https?
|
||||
@@ -143,5 +140,20 @@ namespace System
|
||||
bld.Scheme = predicate ? "https" : "http";
|
||||
return bld;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Escape Url query string
|
||||
/// </summary>
|
||||
/// <param name="bld"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToEscapeString(this UriBuilder bld) => Uri.EscapeUriString(bld.Uri.ToString());
|
||||
|
||||
/// <summary>
|
||||
/// Escape the whole Url string
|
||||
/// </summary>
|
||||
/// <param name="bld"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToEscapeDataString(this UriBuilder bld) => Uri.EscapeDataString(bld.Uri.ToString());
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user