Skip to content

Commit ebbf7c8

Browse files
committed
alerts: don't double up last char at EOF.
1 parent 06ed517 commit ebbf7c8

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/parser/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ where
675675
let mut fence_length = 0;
676676

677677
let bytes = line.as_bytes();
678+
// The checks made here co-operate with the alert_start scanner for soundness.
678679
while bytes[title_startpos] != b']' {
679680
if bytes[title_startpos] == b'>' {
680681
fence_length += 1
@@ -690,8 +691,9 @@ where
690691
}
691692

692693
// anything remaining on this line is considered an alert title
693-
let mut title = entity::unescape_html(&line[title_startpos..]).into_owned();
694-
strings::trim(&mut title);
694+
let mut title = entity::unescape_html(&line[title_startpos..]);
695+
strings::trim_cow(&mut title);
696+
let mut title = title.into_owned();
695697
strings::unescape(&mut title);
696698

697699
let na = NodeAlert {
@@ -702,7 +704,7 @@ where
702704
title: if title.is_empty() { None } else { Some(title) },
703705
};
704706

705-
let offset = self.curline_len - self.offset - 1;
707+
let offset = self.curline_len - self.offset - strings::newlines_of(line);
706708
self.advance_offset(line, offset, false);
707709

708710
*container = self.add_child(

src/tests/alerts.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,22 @@ fn sourcepos_multiline() {
8585
])
8686
);
8787
}
88+
89+
#[test]
90+
fn surprise_eof() {
91+
assert_ast_match!(
92+
[extension.alerts],
93+
"> [!note]\n",
94+
(document (1:1-1:9) [
95+
(alert (1:1-1:9))
96+
])
97+
);
98+
99+
assert_ast_match!(
100+
[extension.alerts],
101+
"> [!note]",
102+
(document (1:1-1:9) [
103+
(alert (1:1-1:9))
104+
])
105+
);
106+
}

0 commit comments

Comments
 (0)