Skip to content

JSON Parsing - deadlock/stuck on parsing Json to HTML #36

Description

@JochnGst

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>());
            }
        }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions