diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpServerUtility.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpServerUtility.cs index 8a3432a27..c016a987c 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpServerUtility.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpServerUtility.cs @@ -3,7 +3,9 @@ using System.Collections.Specialized; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using System.IO; +using System.Net; using System.Web.Hosting; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.SystemWebAdapters; @@ -32,6 +34,11 @@ public string MapPath(string? path) public void ClearError() => _context.AsSystemWeb().ClearError(); + [return: NotNullIfNotNull(nameof(value))] + public string? HtmlEncode(string? value) => WebUtility.HtmlEncode(value); + + public void HtmlEncode(string? value, TextWriter output) => WebUtility.HtmlEncode(value, output); + /// /// This method is similar to but handles the trailing character that /// appends to the string. diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpServerUtilityBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpServerUtilityBase.cs index 136e62f35..ce860cc46 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpServerUtilityBase.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpServerUtilityBase.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics.CodeAnalysis; +using System.IO; namespace System.Web; @@ -10,6 +11,10 @@ public class HttpServerUtilityBase { public virtual string MachineName => throw new NotImplementedException(); + public virtual string? HtmlEncode(string? value) => throw new NotImplementedException(); + + public virtual void HtmlEncode(string? value, TextWriter output) => throw new NotImplementedException(); + public virtual string MapPath(string path) => throw new NotImplementedException(); public virtual Exception? GetLastError() => throw new NotImplementedException(); diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpServerUtilityWrapper.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpServerUtilityWrapper.cs index 64d8e17ea..41d226834 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpServerUtilityWrapper.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpServerUtilityWrapper.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.IO; + namespace System.Web; public class HttpServerUtilityWrapper : HttpServerUtilityBase @@ -20,6 +22,10 @@ public HttpServerUtilityWrapper(HttpServerUtility utility) public override string MachineName => _utility.MachineName; + public override string? HtmlEncode(string? value) => _utility.HtmlEncode(value); + + public override void HtmlEncode(string? value, TextWriter output) => _utility.HtmlEncode(value, output); + public override string MapPath(string path) => _utility.MapPath(path); public override byte[]? UrlTokenDecode(string input) => HttpServerUtility.UrlTokenDecode(input);