Skip to content

Commit

Permalink
Fix panic on eol after tag with GFM tag filter
Browse files Browse the repository at this point in the history
Closes GH-80.
  • Loading branch information
wooorm committed Sep 9, 2023
1 parent 80c7d62 commit 077ef89
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
with:
toolchain: stable
components: rustfmt, clippy
- run: cargo fmt --check && cargo clippy --all --all-features
- run: cargo fmt --check && cargo clippy --examples --tests --benches --all-features
- run: cargo test --all-features
coverage:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ The following bash scripts are useful when working on this project:
```
* format:
```sh
cargo fmt
cargo fmt && cargo fix --all-targets
```
* lint:
```sh
cargo fmt --check && cargo clippy --all --all-features
cargo fmt --check && cargo clippy --examples --tests --benches --all-features
```
* test:
```sh
Expand Down
1 change: 0 additions & 1 deletion src/construct/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ fn exit_containers(tokenizer: &mut Tokenizer, phase: &Phase) -> Result<(), Strin
let mut exits = Vec::with_capacity(stack_close.len());

while let Some(container) = stack_close.pop() {

let name = match container.kind {
Container::BlockQuote => Name::BlockQuote,
Container::GfmFootnoteDefinition => Name::GfmFootnoteDefinition,
Expand Down
7 changes: 5 additions & 2 deletions src/util/gfm_tagfilter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use crate::util::constant::{GFM_HTML_TAGFILTER_NAMES, GFM_HTML_TAGFILTER_SIZE_MAX};
use alloc::string::String;
use core::str;
extern crate std;
use std::println;

/// Make dangerous HTML a tiny bit safer.
///
Expand Down Expand Up @@ -49,10 +51,11 @@ pub fn gfm_tagfilter(value: &str) -> String {
name_end += 1;
}

println!("{:?}, {:?}, {:?}", name_start, name_end, bytes);
// Non-empty.
if name_end != name_start &&
if (name_end == len || (name_end != name_start &&
// HTML whitespace, closing slash, or closing angle bracket.
matches!(bytes[name_end], b'\t' | b'\n' | 12 /* `\f` */ | b'\r' | b' ' | b'/' | b'>') &&
matches!(bytes[name_end], b'\t' | b'\n' | 12 /* `\f` */ | b'\r' | b' ' | b'/' | b'>'))) &&
// Known name.
GFM_HTML_TAGFILTER_NAMES.contains(&str::from_utf8(&bytes[name_start..name_end])
.unwrap()
Expand Down
32 changes: 32 additions & 0 deletions tests/gfm_tagfilter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,38 @@ fn gfm_tagfilter() -> Result<(), String> {
"should filter"
);

assert_eq!(
to_html_with_options(
"<iframe\n>",
&Options {
compile: CompileOptions {
allow_dangerous_html: true,
gfm_tagfilter: true,
..Default::default()
},
..Default::default()
}
)?,
"&lt;iframe\n>",
"should filter when followed by a line ending (1)"
);

assert_eq!(
to_html_with_options(
"<div\n>",
&Options {
compile: CompileOptions {
allow_dangerous_html: true,
gfm_tagfilter: true,
..Default::default()
},
..Default::default()
}
)?,
"<div\n>",
"should filter when followed by a line ending (2)"
);

assert_eq!(
to_html_with_options(
r##"
Expand Down

0 comments on commit 077ef89

Please sign in to comment.