Skip to content

Conversation

ogchrislem
Copy link

Json parsing can fail with incomplete json, timing out with no exception thrown. Adding the word boundary match to the regex prevents this. Unsure of any further implications but complete json is still parsed and coloured successfully after the change

Example failing code before change using ColorCode via Markdig

using Markdown.ColorCode;
using ColorCode.Styling;
using System;

public class Program
{
	public static void Main()
	{
		
		var markdownPipeline = new Markdig.MarkdownPipelineBuilder()            
			.UseColorCode(styleDictionary: StyleDictionary.DefaultDark)			
			.Build();
		
		var result = Markdig.Markdown.ToHtml("```json\n[\n    {\n        \"jsonfield1\": \"value1\",\n        \"jsonfield2\": \"value2\"\n    },\n    {\n        \"jsonfield1\": \"value1 value1 value1 value1 value1 value1 value1 ",markdownPipeline);
		
		Console.WriteLine(result); 
	}
}

Json parsing can fail with incomplete json, and just timeout with no exception thrown. Adding the word boundary match to the regex prevents this. Unsure of any further implications but complete json is still parsed successfully after the change
@ogchrislem
Copy link
Author

@dotnet-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants