Skip to content

Commit 0440cfd

Browse files
committed
fix: 引用ID校验不通过时,不设置同时输出信息
1 parent 3ed70b3 commit 0440cfd

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

framework/src/Bing.Logs.Exceptionless/Bing/Logs/Exceptionless/ExceptionlessProvider.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System;
2+
using System.Linq;
23
using Bing.Configuration;
34
using Bing.Extensions;
45
using Bing.Logs.Abstractions;
@@ -154,7 +155,36 @@ private static string RemoveParams(string url, string[] paramList)
154155
/// </summary>
155156
/// <param name="builder">事件生成器</param>
156157
/// <param name="content">日志内容</param>
157-
private void SetReferenceId(EventBuilder builder, ILogContent content) => builder.SetReferenceId($"{content.LogId}");
158+
private void SetReferenceId(EventBuilder builder, ILogContent content)
159+
{
160+
if (!IsValidIdentifier(content.LogId))
161+
{
162+
builder.SetProperty("ReferenceIdException", content.LogId);
163+
return;
164+
}
165+
builder.SetReferenceId($"{content.LogId}");
166+
}
167+
168+
/// <summary>
169+
/// 校验标识
170+
/// </summary>
171+
/// <param name="value">值</param>
172+
private static bool IsValidIdentifier(string value)
173+
{
174+
if (value == null)
175+
return true;
176+
177+
if (value.Length < 8 || value.Length > 100)
178+
return false;
179+
180+
for (var index = 0; index < value.Length; index++)
181+
{
182+
if (!char.IsLetterOrDigit(value[index]) && value[index] != '-')
183+
return false;
184+
}
185+
return true;
186+
}
187+
158188

159189
/// <summary>
160190
/// 设置异常

0 commit comments

Comments
 (0)