Skip to content

Commit

Permalink
Merge pull request #668 from notriddle/notriddle/lowercase-html-decla…
Browse files Browse the repository at this point in the history
…rations

Allow lowercase letters in HTML declarations
  • Loading branch information
Martin1887 committed Jun 21, 2023
2 parents 34c2bb5 + d4d9b78 commit ab7c7bf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
9 changes: 9 additions & 0 deletions specs/regression.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1054,3 +1054,12 @@ ISSUE 656
→|-----|------|
| baz | alef |</p>
````````````````````````````````


ISSUE 659

```````````````````````````````` example
<!doctype html>
.
<!doctype html>
````````````````````````````````
3 changes: 1 addition & 2 deletions src/firstpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1466,8 +1466,7 @@ fn get_html_end_tag(text_bytes: &[u8]) -> Option<&'static str> {

if text_bytes.len() > 1
&& text_bytes[0] == b'!'
&& text_bytes[1] >= b'A'
&& text_bytes[1] <= b'Z'
&& text_bytes[1].is_ascii_alphabetic()
{
Some(">")
} else {
Expand Down
15 changes: 7 additions & 8 deletions src/scanners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,8 @@ pub(crate) fn scan_inline_html_comment(
let c = *bytes.get(ix)?;
ix += 1;
match c {
// An HTML comment consists of `<!--` + text + `-->`, where text does not start with `>`
// or `->`, does not end with -, and does not contain --.
b'-' => {
let dashes = scan_ch_repeat(&bytes[ix..], b'-');
if dashes < 1 {
Expand All @@ -1336,6 +1338,8 @@ pub(crate) fn scan_inline_html_comment(
}
None
}
// A CDATA section consists of the string `<![CDATA[`, a string of characters not
// including the string `]]>`, and the string `]]>`.
b'[' if bytes[ix..].starts_with(b"CDATA[") && ix > scan_guard.cdata => {
ix += b"CDATA[".len();
ix = memchr(b']', &bytes[ix..]).map_or(bytes.len(), |x| ix + x);
Expand All @@ -1349,14 +1353,9 @@ pub(crate) fn scan_inline_html_comment(
Some(ix + 1)
}
}
b'A'..=b'Z' if ix > scan_guard.declaration => {
// Scan declaration.
ix += scan_while(&bytes[ix..], |c| c >= b'A' && c <= b'Z');
let whitespace = scan_while(&bytes[ix..], is_ascii_whitespace);
if whitespace == 0 {
return None;
}
ix += whitespace;
// A declaration consists of the string `<!`, an ASCII letter, zero or more characters not
// including the character >, and the character >.
_ if c.is_ascii_alphabetic() && ix > scan_guard.declaration => {
ix = memchr(b'>', &bytes[ix..]).map_or(bytes.len(), |x| ix + x);
if scan_ch(&bytes[ix..], b'>') == 0 {
scan_guard.declaration = ix;
Expand Down
10 changes: 10 additions & 0 deletions tests/suite/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,3 +1241,13 @@ fn regression_test_83() {

test_markdown_html(original, expected, false, false, false);
}

#[test]
fn regression_test_84() {
let original = r##"<!doctype html>
"##;
let expected = r##"<!doctype html>
"##;

test_markdown_html(original, expected, false, false, false);
}

0 comments on commit ab7c7bf

Please sign in to comment.