Skip to content

Commit 91ad747

Browse files
committed
autolink: identify & permit rem == 0 case.
1 parent 642ba7b commit 91ad747

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/parser/autolink.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,17 @@ pub(crate) fn process_email_autolinks<'a>(
123123
// - if remaining `i` is equal to the byte count `x`,
124124
// set `e = sp.end.column` and finish.
125125
// - if remaining `i` is less than the byte count `x`,
126-
// assert `sp.end.column - sp.start.column + 1 == x` (1),
126+
// assert `sp.end.column - sp.start.column + 1 == x || rem == 0` (1),
127127
// set `e = sp.start.column + i - 1` and finish.
128128
//
129129
// (1) If `x` doesn't equal the range covered between the start and end column,
130130
// there's no way to determine sourcepos within the range. This is a bug if
131131
// it happens; it suggests we've matched an email autolink with some smart
132132
// punctuation in it, or worse.
133+
//
134+
// The one exception is if `rem == 0`. Given nothing to consume, we can
135+
// happily restore what we popped, returning `sp.start.column - 1` for the
136+
// end column of the original node.
133137
fn consume_spx(spx: &mut VecDeque<(Sourcepos, usize)>, mut rem: usize) -> usize {
134138
while let Some((sp, x)) = spx.pop_front() {
135139
if rem > x {
@@ -138,7 +142,7 @@ fn consume_spx(spx: &mut VecDeque<(Sourcepos, usize)>, mut rem: usize) -> usize
138142
return sp.end.column;
139143
} else {
140144
// rem < x
141-
assert_eq!(sp.end.column - sp.start.column + 1, x);
145+
assert!((sp.end.column - sp.start.column + 1 == x) || rem == 0);
142146
spx.push_front((
143147
(
144148
sp.start.line,

src/tests/fuzz.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,12 @@ fn echaw4() {
276276
fn echaw5() {
277277
assert_ast_match!(
278278
[],
279-
// [extension.autolink],
280279
281280
(document (1:1-1:9) [
282281
(paragraph (1:1-1:9) [
283282
(emph (1:1-1:3) [
284283
(text (1:2-1:2) "#")
285284
])
286-
// (link (1:1-1:14) "mailto:-@_.e" [
287-
// (text (1:1-1:14) "-@_.e")
288-
// ])
289285
(text (1:4-1:9) "[email protected]")
290286
])
291287
])
@@ -309,3 +305,18 @@ fn echaw6() {
309305
])
310306
);
311307
}
308+
309+
#[test]
310+
fn echaw7() {
311+
assert_ast_match!(
312+
[extension.autolink],
313+
314+
(document (1:1-1:10) [
315+
(paragraph (1:1-1:10) [
316+
(link (1:1-1:10) "mailto:[email protected]" [
317+
(text (1:1-1:10) "[email protected]")
318+
])
319+
])
320+
])
321+
);
322+
}

0 commit comments

Comments
 (0)