JSON Parsing - deadlock/stuck on parsing Json to HTML
还没有人认领这个 Issue。
评估
调研方向
从 issue 中所示的 Parse 方法开始,使用提供的 JSON 字符串、HtmlFormatter 以及 ColorCode.Languages.FindById 中的 json 语言重现卡死。跟踪编译后的语言正则表达式经过 regexMatch.NextMatch() 的过程,并确认解析能够在不陷入停滞的情况下完成,同时仍生成预期的 HTML 输出。
由索引模型根据 Issue 内容生成。
描述
Im trying to parse this JSON sipped to my Blazor page. But because of some weird RegEx parsing issue the process get stuck without any Exception. Can somebody tell me where there could be a Problem?
here you can find my test project: ColorCodeTest
This is my Test Code
string _jsonString3 = "{\r\n \"raw_causes\": [\r\n \"Winterglatter Fahrbahn\",\r\n \"Nicht angepasste Geschwindigkeit\",\r\n \"test3\"\r\n ]\r\n }";
try
{
var _formatter = new HtmlFormatter();
var language = ColorCode.Languages.FindById("json");
_jsonHtml = _formatter.GetHtmlString(_jsonString3, language);
}
catch (Exception)
{
throw;
}
It stuck after the array Element \"Winterglatter Fahrbahn\", when it call regexMatch = regexMatch.NextMatch(); and I have no idear why this happends
private void Parse(string sourceCode,
CompiledLanguage compiledLanguage,
Action<string, IList<Scope>> parseHandler)
{
Match regexMatch = compiledLanguage.Regex.Match(sourceCode);
if (!regexMatch.Success)
parseHandler(sourceCode, new List<Scope>());
else
{
int currentIndex = 0;
try
{
while (regexMatch.Success)
{
string sourceCodeBeforeMatch = sourceCode.Substring(currentIndex, regexMatch.Index - currentIndex);
if (!string.IsNullOrEmpty(sourceCodeBeforeMatch))
parseHandler(sourceCodeBeforeMatch, new List<Scope>());
string matchedSourceCode = sourceCode.Substring(regexMatch.Index, regexMatch.Length);
if (!string.IsNullOrEmpty(matchedSourceCode))
{
List<Scope> capturedStylesForMatchedFragment = GetCapturedStyles(regexMatch, regexMatch.Index, compiledLanguage);
List<Scope> capturedStyleTree = CreateCapturedStyleTree(capturedStylesForMatchedFragment);
parseHandler(matchedSourceCode, capturedStyleTree);
}
currentIndex = regexMatch.Index + regexMatch.Length;
regexMatch = regexMatch.NextMatch();
}
}
catch (Exception ex)
{
throw;
}
string sourceCodeAfterAllMatches = sourceCode.Substring(currentIndex);
if (!string.IsNullOrEmpty(sourceCodeAfterAllMatches))
parseHandler(sourceCodeAfterAllMatches, new List<Scope>());
}
}
- 主要语言
- C#
- 星标
- 267
- 派生
- 58
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
CommunityToolkit/ColorCode-Universal 的其他 Issue
-
Json.cs: Catastrophic regex backtracking in Regex_String causes extreme slowdown with JSON arrays 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
-
难度 5/5 一周以上 新手友好度 20/100
-
难度 3/5 1-2 天 新手友好度 30/100
-
难度 3/5 1-2 天 新手友好度 38/100
-
难度 3/5 1-2 天 新手友好度 38/100
查看 CommunityToolkit/ColorCode-Universal 的全部 Issue
相似的 Issue
-
type/automation type/tech-debt
难度 2/5 1-3 小时 新手友好度 78/100
-
bug
难度 2/5 1-3 小时 新手友好度 88/100
-
t/bug
难度 2/5 1-3 小时 新手友好度 82/100
-
ci-failure-cause test-failure
难度 2/5 1-3 小时 新手友好度 82/100
-
area:auth FE mvp P3
难度 2/5 1-3 小时 新手友好度 88/100
klasolsson81/jobbliggaren#1788 ·