diff options
| author | Fuwn <[email protected]> | 2025-09-11 05:57:01 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-09-11 05:57:01 +0000 |
| commit | 28581ff44e9b6d98879807ecc78c8cd709af371a (patch) | |
| tree | 2ba228efc41ef90623106bb9c1ed75dc3b8f251c /src | |
| parent | fix(ast): Gracefully handle malformed link lines (diff) | |
| download | germ-28581ff44e9b6d98879807ecc78c8cd709af371a.tar.xz germ-28581ff44e9b6d98879807ecc78c8cd709af371a.zip | |
fix(ast): Improve UTF-8 handling
Diffstat (limited to 'src')
| -rw-r--r-- | src/ast/container.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/ast/container.rs b/src/ast/container.rs index bf4166c..46c548b 100644 --- a/src/ast/container.rs +++ b/src/ast/container.rs @@ -224,10 +224,14 @@ impl Ast { nodes.push(Node::Heading { level, - // Here, we are `get`ing the `&str` starting at the `level`-th - // index, then trimming the start. These operations - // effectively off the line identifier. - text: line.get(level..).unwrap_or("").trim_start().to_string(), + // Here, the text after the heading markers is safely extracted. + // `chars().skip()` is used to safely handle UTF-8 boundaries. + text: line + .chars() + .skip(level) + .collect::<String>() + .trim_start() + .to_string(), }); break; |