-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sourcepos: remove and document unsound sourcepos calculations
- Loading branch information
Showing
6 changed files
with
112 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,29 @@ fn autolink_no_link_bad() { | |
|
||
#[test] | ||
fn sourcepos_correctly_restores_context() { | ||
// There's unsoundness in trying to maintain and adjust sourcepos | ||
// when doing autolinks in the light of: | ||
// | ||
// a) Some source elements introducing a different number of characters | ||
// to the content text than they take in source, i.e. smart | ||
// punctuation. | ||
// | ||
// b) Text node consolidation happening before autolinking. | ||
// | ||
// (b) is obviously non-optional, but it means we end up with Text | ||
// nodes with different byte counts than their sourcepos span lengths. | ||
// | ||
// One possible solution would be to actually accumulate multiple | ||
// sourcepos spans per Text node, each also tracking the number of | ||
// bytes of content text it's responsible for. This would work well | ||
// enough as long as we never had to adjust a sourcepos into a spot | ||
// within a sourcepos span that had a target text width where it | ||
// wasn't equal. That probably wouldn't happen, though -- i.e. we're | ||
// never autolinking into the middle of a rendered smart punctuation. | ||
// | ||
// For now the desired sourcepos is documented in comment. What we | ||
// have currently (after backing out the adjustments, having hit the | ||
// above case) matches cmark-gfm. | ||
assert_ast_match!( | ||
[], | ||
"ab _cde_ [email protected] h*ijklm* n", | ||
|
@@ -81,11 +104,11 @@ fn sourcepos_correctly_restores_context() { | |
(emph (1:4-1:8) [ | ||
(text (1:5-1:7) "cde") | ||
]) | ||
(text (1:9-1:9) " ") | ||
(link (1:10-1:15) [ | ||
(text (1:10-1:15) "[email protected]") | ||
(text (1:9-1:17) " ") // (text (1:9-1:9) " ") | ||
(link (XXX) [ // (link (1:10-1:15) [ | ||
(text (XXX) "[email protected]") // (text (1:10-1:15) "[email protected]") | ||
]) | ||
(text (1:16-1:17) " h") | ||
(text (XXX) " h") // (text (1:16-1:17) " h") | ||
(emph (1:18-1:24) [ | ||
(text (1:19-1:23) "ijklm") | ||
]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,5 @@ | ||
use super::{html, html_opts}; | ||
|
||
/// To be used when moving from the all_options fuzz target to here. | ||
/// Reduce to the actual necessary options to reproduce. | ||
#[allow(dead_code)] | ||
#[cfg(feature = "shortcodes")] | ||
fn all_options() -> crate::ComrakOptions { | ||
crate::ComrakOptions { | ||
extension: crate::ComrakExtensionOptions { | ||
strikethrough: true, | ||
tagfilter: true, | ||
table: true, | ||
autolink: true, | ||
tasklist: true, | ||
superscript: true, | ||
header_ids: Some("user-content-".to_string()), | ||
footnotes: true, | ||
description_lists: true, | ||
front_matter_delimiter: Some("---".to_string()), | ||
shortcodes: true, | ||
}, | ||
parse: crate::ComrakParseOptions { | ||
smart: true, | ||
default_info_string: Some("rust".to_string()), | ||
relaxed_tasklist_matching: true, | ||
}, | ||
render: crate::ComrakRenderOptions { | ||
hardbreaks: true, | ||
github_pre_lang: true, | ||
full_info_string: true, | ||
width: 80, | ||
unsafe_: true, | ||
escape: true, | ||
list_style: crate::ListStyleType::Star, | ||
sourcepos: true, | ||
}, | ||
} | ||
} | ||
|
||
#[test] | ||
fn pointy_brace_open() { | ||
html("<!-", "<p><!-</p>\n"); | ||
|
@@ -97,3 +60,21 @@ fn line_end() { | |
fn bracket_match() { | ||
html("[;\0V\n]::g\n[;\0V\n]", "<p><a href=\":g\">;�V\n</a></p>\n"); | ||
} | ||
|
||
#[test] | ||
fn trailing_hyphen() { | ||
html_opts!( | ||
[extension.autolink, parse.smart, render.sourcepos], | ||
"[email protected]", | ||
"<p data-sourcepos=\"1:1-1:5\">[email protected]</p>\n" | ||
); | ||
} | ||
|
||
#[test] | ||
fn trailing_hyphen_matches() { | ||
html_opts!( | ||
[extension.autolink, parse.smart, render.sourcepos], | ||
"[email protected]", | ||
"<p data-sourcepos=\"1:1-1:6\"><a href=\"mailto:[email protected]\">[email protected]</a>–</p>\n" | ||
); | ||
} |