Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
markdown: Fix out of range panic in parser (#30510)
Bennet Bo Fenner06af0310f7b2
diff --git a/crates/markdown/src/parser.rs b/crates/markdown/src/parser.rsindex debfe5245f5..ca7bd406c4b 100644--- a/crates/markdown/src/parser.rs+++ b/crates/markdown/src/parser.rs@@ -510,6 +510,9 @@ pub(crate) fn extract_code_block_content_range(text: &str) -> Range<usize> {if !range.is_empty() && text.ends_with("```") {range.end -= 3;}+ if range.start > range.end {+ range.end = range.start;+ }range}@@ -686,6 +689,10 @@ mod tests {let input = "```python\nprint('hello')\nprint('world')\n```";assert_eq!(extract_code_block_content_range(input), 10..40);++ // Malformed input+ let input = "`````";+ assert_eq!(extract_code_block_content_range(input), 3..3);}#[test]