diff --git a/src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs b/src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs index d03236dd9909c..f1590c8080bb3 100644 --- a/src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs +++ b/src/libraries/System.Web.HttpUtility/src/System/Web/Util/HttpEncoder.cs @@ -130,15 +130,10 @@ private static int IndexOfHtmlAttributeEncodingChars(string s) => internal static string JavaScriptStringEncode(string? value, bool addDoubleQuotes) { - if (string.IsNullOrEmpty(value)) - { - return addDoubleQuotes ? @"""""" : string.Empty; - } - int i = value.AsSpan().IndexOfAny(s_invalidJavaScriptChars); if (i < 0) { - return addDoubleQuotes ? $"\"{value}\"" : value; + return addDoubleQuotes ? $"\"{value}\"" : value ?? string.Empty; } return EncodeCore(value, i, addDoubleQuotes);