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 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。