Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions 24 src/NLog/Internal/UrlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
namespace NLog.Internal
{
using System;
using System.ComponentModel;
using System.Text;

/// <summary>
Expand All @@ -54,6 +55,8 @@ public enum EscapeEncodingOptions
/// <summary>Replace space ' ' with '+' instead of '%20'</summary>
SpaceAsPlus = 8,
/// <summary>Skip UTF8 encoding, and prefix special characters with '%u'</summary>
[Obsolete("Instead use default Rfc2396 or Rfc3986. Marked obsolete with NLog v5.3")]
[EditorBrowsable(EditorBrowsableState.Never)]
NLogLegacy = 16 | LegacyRfc2396 | LowerCaseHex | UriString,
};

Expand All @@ -67,11 +70,12 @@ public static void EscapeDataEncode(string source, StringBuilder target, EscapeE
{
if (string.IsNullOrEmpty(source))
return;



bool isLowerCaseHex = Contains(options, EscapeEncodingOptions.LowerCaseHex);
bool isSpaceAsPlus = Contains(options, EscapeEncodingOptions.SpaceAsPlus);
#pragma warning disable CS0618 // Type or member is obsolete
bool isNLogLegacy = Contains(options, EscapeEncodingOptions.NLogLegacy);
#pragma warning restore CS0618 // Type or member is obsolete

char[] charArray = null;
byte[] byteArray = null;
Expand All @@ -97,7 +101,9 @@ public static void EscapeDataEncode(string source, StringBuilder target, EscapeE

if (isNLogLegacy)
{
#pragma warning disable CS0618 // Type or member is obsolete
HandleLegacyEncoding(target, ch, hexChars);
#pragma warning restore CS0618 // Type or member is obsolete
continue;
}

Expand All @@ -121,10 +127,6 @@ private static bool Contains(EscapeEncodingOptions options, EscapeEncodingOption
/// <summary>
/// Convert the wide-char into utf8-bytes, and then escape
/// </summary>
/// <param name="target"></param>
/// <param name="charArray"></param>
/// <param name="byteArray"></param>
/// <param name="hexChars"></param>
private static void WriteWideChars(StringBuilder target, char[] charArray, byte[] byteArray, char[] hexChars)
{
int byteCount = Encoding.UTF8.GetBytes(charArray, 0, 1, byteArray, 0);
Expand All @@ -140,6 +142,7 @@ private static void WriteWideChars(StringBuilder target, char[] charArray, byte[
}
}

[Obsolete("Instead use default Rfc2396 or Rfc3986. Marked obsolete with NLog v5.3")]
private static void HandleLegacyEncoding(StringBuilder target, char ch, char[] hexChars)
{
if (ch < 256)
Expand Down Expand Up @@ -221,11 +224,20 @@ public static EscapeEncodingOptions GetUriStringEncodingFlags(bool escapeDataNLo
{
EscapeEncodingOptions encodingOptions = EscapeEncodingOptions.UriString;
if (escapeDataNLogLegacy)
{
#pragma warning disable CS0618 // Type or member is obsolete
encodingOptions |= EscapeEncodingOptions.LowerCaseHex | EscapeEncodingOptions.NLogLegacy;
#pragma warning restore CS0618 // Type or member is obsolete
}
else if (!escapeDataRfc3986)
{
encodingOptions |= EscapeEncodingOptions.LowerCaseHex | EscapeEncodingOptions.LegacyRfc2396;
}

if (spaceAsPlus)
{
encodingOptions |= EscapeEncodingOptions.SpaceAsPlus;
}
return encodingOptions;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

namespace NLog.LayoutRenderers.Wrappers
{
using System;
using System.ComponentModel;
using System.Text;
using NLog.Config;
using NLog.Internal;
Expand Down Expand Up @@ -72,14 +74,19 @@ public UrlEncodeLayoutRendererWrapper()
/// </summary>
/// <value>A value of <c>true</c> if legacy encoding; otherwise, <c>false</c> for standard UTF8 encoding.</value>
/// <docgen category='Layout Options' order='100' />
[Obsolete("Instead use default Rfc2396 or EscapeDataRfc3986. Marked obsolete with NLog v5.3")]
[EditorBrowsable(EditorBrowsableState.Never)]
public bool EscapeDataNLogLegacy { get; set; }

/// <inheritdoc/>
protected override string Transform(string text)
{
if (!string.IsNullOrEmpty(text))
{
UrlHelper.EscapeEncodingOptions encodingOptions = UrlHelper.GetUriStringEncodingFlags(EscapeDataNLogLegacy, SpaceAsPlus, EscapeDataRfc3986);
#pragma warning disable CS0618 // Type or member is obsolete
bool escapeDataNLogLegacy = EscapeDataNLogLegacy;
#pragma warning restore CS0618 // Type or member is obsolete
UrlHelper.EscapeEncodingOptions encodingOptions = UrlHelper.GetUriStringEncodingFlags(escapeDataNLogLegacy, SpaceAsPlus, EscapeDataRfc3986);
System.Text.StringBuilder sb = new System.Text.StringBuilder(text.Length + 20);
UrlHelper.EscapeDataEncode(text, sb, encodingOptions);
return sb.ToString();
Expand All @@ -95,7 +102,11 @@ protected override void RenderInnerAndTransform(LogEventInfo logEvent, StringBui
{
var text = builder.ToString(orgLength, builder.Length - orgLength);
builder.Length = orgLength;
UrlHelper.EscapeEncodingOptions encodingOptions = UrlHelper.GetUriStringEncodingFlags(EscapeDataNLogLegacy, SpaceAsPlus, EscapeDataRfc3986);

#pragma warning disable CS0618 // Type or member is obsolete
bool escapeDataNLogLegacy = EscapeDataNLogLegacy;
#pragma warning restore CS0618 // Type or member is obsolete
UrlHelper.EscapeEncodingOptions encodingOptions = UrlHelper.GetUriStringEncodingFlags(escapeDataNLogLegacy, SpaceAsPlus, EscapeDataRfc3986);
UrlHelper.EscapeDataEncode(text, builder, encodingOptions);
}
}
Expand Down
14 changes: 12 additions & 2 deletions 14 src/NLog/Targets/WebServiceTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace NLog.Targets
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Net;
using System.Text;
Expand Down Expand Up @@ -197,6 +198,8 @@ public WebServiceProxyType ProxyType
/// </summary>
/// <value>A value of <c>true</c> if legacy encoding; otherwise, <c>false</c> for standard UTF8 encoding.</value>
/// <docgen category='Web Service Options' order='100' />
[Obsolete("Instead use default Rfc2396 or EscapeDataRfc3986. Marked obsolete with NLog v5.3")]
[EditorBrowsable(EditorBrowsableState.Never)]
public bool EscapeDataNLogLegacy { get; set; }

/// <summary>
Expand Down Expand Up @@ -488,12 +491,16 @@ private Uri BuildWebServiceUrl(LogEventInfo logEvent, object[] parameterValues)
return uri;
}

#pragma warning disable CS0618 // Type or member is obsolete
bool escapeDataNLogLegacy = EscapeDataNLogLegacy;
#pragma warning restore CS0618 // Type or member is obsolete

//if the protocol is HttpGet, we need to add the parameters to the query string of the url
string queryParameters;
using (var targetBuilder = ReusableLayoutBuilder.Allocate())
{
StringBuilder sb = targetBuilder.Result ?? new StringBuilder();
UrlHelper.EscapeEncodingOptions encodingOptions = UrlHelper.GetUriStringEncodingFlags(EscapeDataNLogLegacy, false, EscapeDataRfc3986);
UrlHelper.EscapeEncodingOptions encodingOptions = UrlHelper.GetUriStringEncodingFlags(escapeDataNLogLegacy, false, EscapeDataRfc3986);
BuildWebServiceQueryParameters(parameterValues, sb, encodingOptions);
queryParameters = sb.ToString();
}
Expand Down Expand Up @@ -603,7 +610,10 @@ private sealed class HttpPostFormEncodedFormatter : HttpPostTextFormatterBase

public HttpPostFormEncodedFormatter(WebServiceTarget target) : base(target)
{
_encodingOptions = UrlHelper.GetUriStringEncodingFlags(target.EscapeDataNLogLegacy, true, target.EscapeDataRfc3986);
#pragma warning disable CS0618 // Type or member is obsolete
bool escapeDataNLogLegacy = target.EscapeDataNLogLegacy;
#pragma warning restore CS0618 // Type or member is obsolete
_encodingOptions = UrlHelper.GetUriStringEncodingFlags(escapeDataNLogLegacy, true, target.EscapeDataRfc3986);
}

protected override string GetContentType(WebServiceTarget target)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.