Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ doc = false
typed-arena = "2.0.2"
entities = "1.0.1"
unicode_categories = "0.1.1"
memchr = "2"
shell-words = { version = "1.0", optional = true }
slug = "0.1.4"
emojis = { version = "0.6.2", optional = true }
arbitrary = { version = "1", optional = true, features = ["derive"] }
bon = { version = "3", optional = true }
caseless = "0.2.1"
fmt2io = { version = "1.0.0", optional = true }
jetscii = "0.5.3"

[dev-dependencies]
ntest = "0.9"
percent-encoding-rfc3986 = "0.1.3"
strum = { version = "0.26.3", features = ["derive"] }
toml = "0.7.3"
slug = "0.1.4"

[features]
default = ["cli", "syntect", "bon"]
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"clippy"
"rustfmt"
"rust-src"
"llvm-tools-preview"
])
]
++ (with pkgs; [
Expand Down
63 changes: 24 additions & 39 deletions src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ fn render_html_block<'a, T>(
} else if !context.options.render.unsafe_ {
context.write_str("<!-- raw HTML omitted -->")?;
} else if context.options.extension.tagfilter {
tagfilter_block(literal, context)?;
tagfilter_block(context, literal)?;
} else {
context.write_str(literal)?;
}
Expand Down Expand Up @@ -1690,34 +1690,21 @@ fn tagfilter(literal: &str) -> bool {
false
}

fn tagfilter_block(input: &str, o: &mut dyn Write) -> fmt::Result {
let bytes = input.as_bytes();
let size = input.len();
let mut i = 0;

while i < size {
let org = i;
while i < size && bytes[i] != b'<' {
i += 1;
}

if i > org {
o.write_str(&input[org..i])?;
}

if i >= size {
break;
}
fn tagfilter_block(output: &mut dyn Write, buffer: &str) -> fmt::Result {
let bytes = buffer.as_bytes();
let matcher = jetscii::bytes!(b'<');

if tagfilter(&input[i..]) {
o.write_str("&lt;")?;
let mut offset = 0;
while let Some(i) = matcher.find(&bytes[offset..]) {
output.write_str(&buffer[offset..offset + i])?;
if tagfilter(&buffer[offset + i..]) {
output.write_str("&lt;")?;
} else {
o.write_str("<")?;
output.write_str("<")?;
}

i += 1;
offset += i + 1;
}

output.write_str(&buffer[offset..])?;
Ok(())
}

Expand All @@ -1741,22 +1728,20 @@ pub fn dangerous_url(input: &str) -> bool {
/// URLs in attributes. See escape_href.
pub fn escape(output: &mut dyn Write, buffer: &str) -> fmt::Result {
let bytes = buffer.as_bytes();
const HTML_UNSAFE: [bool; 256] = character_set!(b"&<>\"");
let matcher = jetscii::bytes!(b'"', b'&', b'<', b'>');

let mut offset = 0;
for (i, &byte) in bytes.iter().enumerate() {
if HTML_UNSAFE[byte as usize] {
let esc: &str = match byte {
b'"' => "&quot;",
b'&' => "&amp;",
b'<' => "&lt;",
b'>' => "&gt;",
_ => unreachable!(),
};
output.write_str(&buffer[offset..i])?;
output.write_str(esc)?;
offset = i + 1;
}
while let Some(i) = matcher.find(&bytes[offset..]) {
let esc: &str = match bytes[offset + i] {
b'"' => "&quot;",
b'&' => "&amp;",
b'<' => "&lt;",
b'>' => "&gt;",
_ => unreachable!(),
};
output.write_str(&buffer[offset..offset + i])?;
output.write_str(esc)?;
offset += i + 1;
}
output.write_str(&buffer[offset..])?;
Ok(())
Expand Down