aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-21 16:15:39 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-06-21 16:15:39 +0200
commit7effd171218fff68f051671f1373cee467a8f921 (patch)
tree904e2ef93375f9cf91b96606983684cf9b6261d0
parent92dbf5f2fd211b236de7ddc69967fedfdd286be9 (diff)
downloadmarkdown-rs-7effd171218fff68f051671f1373cee467a8f921.tar.gz
markdown-rs-7effd171218fff68f051671f1373cee467a8f921.tar.bz2
markdown-rs-7effd171218fff68f051671f1373cee467a8f921.zip
Refactor to move protocols to constants
Diffstat (limited to '')
-rw-r--r--readme.md2
-rw-r--r--src/compiler.rs8
-rw-r--r--src/constant.rs12
3 files changed, 15 insertions, 7 deletions
diff --git a/readme.md b/readme.md
index 079790c..6689c7f 100644
--- a/readme.md
+++ b/readme.md
@@ -84,7 +84,6 @@ cargo doc --document-private-items
#### Refactor
-- [ ] (1) Move safe protocols to constants
- [ ] (1) Make text data, string data constructs (document in
`construct/mod.rs`)
- [ ] (1) Configurable tokens (destination, label, title)
@@ -237,6 +236,7 @@ cargo doc --document-private-items
- [x] (1) Make sure crlf/cr/lf are working perfectly
- [x] (1) Figure out lifetimes of things (see `life time` in source)
- [x] (1) Use traits for a bunch of enums, e.g., markers
+- [x] (1) Move safe protocols to constants
### Extensions
diff --git a/src/compiler.rs b/src/compiler.rs
index 9bc2488..4359942 100644
--- a/src/compiler.rs
+++ b/src/compiler.rs
@@ -1,4 +1,5 @@
//! Turn events into a string of HTML.
+use crate::constant::SAFE_PROTOCOL_HREF;
use crate::construct::character_reference::Kind as CharacterReferenceKind;
use crate::tokenizer::{Code, Event, EventType, TokenType};
use crate::util::{
@@ -125,14 +126,9 @@ pub fn compile(events: &[Event], codes: &[Code], options: &Options) -> String {
let protocol_href = if options.allow_dangerous_protocol {
None
} else {
- Some(vec!["http", "https", "irc", "ircs", "mailto", "xmpp"])
+ Some(SAFE_PROTOCOL_HREF.to_vec())
};
let mut line_ending_inferred: Option<LineEnding> = None;
- // let protocol_src = if options.allow_dangerous_protocol {
- // None
- // } else {
- // Some(vec!["http", "https"])
- // };
// let mut slurp_all_line_endings = false;
while index < events.len() {
diff --git a/src/constant.rs b/src/constant.rs
index 9c861be..6ba1638 100644
--- a/src/constant.rs
+++ b/src/constant.rs
@@ -193,6 +193,18 @@ pub const HTML_RAW_SIZE_MAX: usize = 8;
/// To safeguard performance, labels are capped at a large number: `999`.
pub const LINK_REFERENCE_SIZE_MAX: usize = 999;
+/// List of protocols allowed, when operating safely, as `href` on `a`.
+///
+/// This list is based on what is allowed by GitHub.
+pub const SAFE_PROTOCOL_HREF: [&str; 6] = ["http", "https", "irc", "ircs", "mailto", "xmpp"];
+
+/// List of protocols allowed, when operating safely, as `src` on `img`.
+///
+/// This list is based on what is allowed by GitHub.
+// To do: image.
+#[allow(dead_code)]
+pub const SAFE_PROTOCOL_SRC: [&str; 2] = ["http", "https"];
+
/// The number of characters that form a tab stop.
///
/// This relates to the number of whitespace characters needed to form certain