Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/e1r0nd/voca_rs
Browse files Browse the repository at this point in the history
  • Loading branch information
a-merezhanyi committed Nov 10, 2022
2 parents ace1ab1 + 9dd2107 commit 61a2f2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/strip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ fn strip_html_tags(subject: &str) -> String {
let mut depth = 0;
let mut output = String::with_capacity(length);
let mut quote = String::with_capacity(4);
for (i, c) in crate::split::graphemes(subject).iter().enumerate() {
let g = graphemes(subject);
let g_length = g.len();
for (i, c) in g.iter().enumerate() {
let mut advance = false;
match *c {
"<" => {
if !quote.is_empty() {
} else if i + 2 < length
} else if i + 2 < g_length
&& crate::query::query(
unicode_string_range(subject, i, i + 2).as_str(),
"< ",
Expand All @@ -102,7 +104,7 @@ fn strip_html_tags(subject: &str) -> String {
}
"!" => {
if state == StateMode::Html
&& i + 2 < length
&& i + 2 < g_length
&& crate::query::query(
unicode_string_range(subject, i, i + 2).as_str(),
"<!",
Expand All @@ -116,7 +118,7 @@ fn strip_html_tags(subject: &str) -> String {
}
"-" => {
if state == StateMode::Exclamation
&& i + 3 < length
&& i + 3 < g_length
&& crate::query::query(
unicode_string_range(subject, i, i + 3).as_str(),
"!--",
Expand All @@ -142,7 +144,7 @@ fn strip_html_tags(subject: &str) -> String {
}
"E" | "e" => {
if state == StateMode::Exclamation
&& i + 7 < length
&& i + 7 < g_length
&& crate::query::query(
unicode_string_range(subject, i, i + 7).as_str(),
"doctype",
Expand All @@ -161,7 +163,7 @@ fn strip_html_tags(subject: &str) -> String {
} else if state == StateMode::Html
|| state == StateMode::Exclamation
|| state == StateMode::Comment
&& i + 3 < length
&& i + 3 < g_length
&& crate::query::query(
unicode_string_range(subject, i, i + 3).as_str(),
"-->",
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/strip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,8 @@ fn partial_directive() {
assert_eq!(voca_rs::strip::strip_tags("</a"), "");
assert_eq!(voca_rs::strip::strip_tags("<!"), "");
assert_eq!(voca_rs::strip::strip_tags("<!-"), "");
assert_eq!(voca_rs::strip::strip_tags("á<!"), "á");
// Should maybe keep the lose both angle brackets?
assert_eq!(voca_rs::strip::strip_tags(">天地不仁<"), ">天地不仁");
assert_eq!(voca_rs::strip::strip_tags("\u{00a0}<!"), "\u{a0}");
}

0 comments on commit 61a2f2c

Please sign in to comment.