CommunityToolkit / CommunityToolkit/ColorCode-Universal

JSON Parsing - deadlock/stuck on parsing Json to HTML

未關閉
#36 6 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
C#
星號
265
分支
57
PR 合併指標
30 天內沒有已合併 PR

描述

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](https://github.com/JochnGst/ColorCodeTest)

This is my Test Code
```csharp
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
```csharp
private void Parse(string sourceCode,
CompiledLanguage compiledLanguage,
Action> parseHandler)
{
Match regexMatch = compiledLanguage.Regex.Match(sourceCode);

if (!regexMatch.Success)
parseHandler(sourceCode, new List());
else
{
int currentIndex = 0;

try
{
while (regexMatch.Success)
{
string sourceCodeBeforeMatch = sourceCode.Substring(currentIndex, regexMatch.Index - currentIndex);
if (!string.IsNullOrEmpty(sourceCodeBeforeMatch))
parseHandler(sourceCodeBeforeMatch, new List());

string matchedSourceCode = sourceCode.Substring(regexMatch.Index, regexMatch.Length);
if (!string.IsNullOrEmpty(matchedSourceCode))
{
List capturedStylesForMatchedFragment = GetCapturedStyles(regexMatch, regexMatch.Index, compiledLanguage);
List 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());
}
}

```

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

從 issue 中所示的 Parse 方法開始,使用提供的 JSON 字串、HtmlFormatter 以及 ColorCode.Languages.FindById 中的 json 語言重現卡死。追蹤編譯後的語言正規表示式經過 regexMatch.NextMatch() 的過程,並確認剖析能在不陷入停滯的情況下完成,同時仍產生預期的 HTML 輸出。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
csharp
領域
devtools
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。