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
3 changes: 3 additions & 0 deletions src/Html/HtmlParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ module internal HtmlParser =
and tagName isEndTag state =
match state.Peek() with
| TextParser.Whitespace _ -> state.Pop(); beforeAttributeName state
| TextParser.EndOfFile _ -> state.EmitTag(isEndTag)
| '/' -> state.Pop(); selfClosingStartTag state
| '>' -> state.Pop(); state.EmitTag(isEndTag)
| _ -> state.ConsTag(); tagName isEndTag state
Expand Down Expand Up @@ -684,6 +685,7 @@ module internal HtmlParser =
| '>' -> state.Pop(); state.EmitTag(false)
| TextParser.LetterDigit _ -> state.ConsAttrName(); attributeName state
| TextParser.Whitespace _ -> afterAttributeName state
| TextParser.EndOfFile _ -> state.EmitTag(false)
| _ -> state.ConsAttrName(); attributeName state
and afterAttributeName state =
match state.Peek() with
Expand All @@ -695,6 +697,7 @@ module internal HtmlParser =
and beforeAttributeValue state =
match state.Peek() with
| TextParser.Whitespace _ -> state.Pop(); beforeAttributeValue state
| TextParser.EndOfFile _ -> state.EmitTag(false)
| '/' -> state.Pop(); selfClosingStartTag state
| '>' -> state.Pop(); state.EmitTag(false)
| '"' -> state.Pop(); attributeValueQuoted '"' state
Expand Down
10 changes: 10 additions & 0 deletions tests/FSharp.Data.Tests/HtmlParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -907,3 +907,13 @@ let ``Parsing non-html content doesn't cause an infinite loop - Github-1264``()
HtmlNode.NewText content
]
result |> should equal expected

[<Test; Timeout(2000)>]
let ``Can handle incomplete tags at end of file without creating an infinite loop``() =
let result = HtmlDocument.Parse """<html><head></head></html"""
let expected =
HtmlDocument.New
[ HtmlNode.NewElement
("html",
[ HtmlNode.NewElement("head")])]
result |> should equal expected