Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/fsharp/FSharp.Data
Browse files Browse the repository at this point in the history
  • Loading branch information
dsyme committed Sep 24, 2019
2 parents 993cf47 + 75bd4df commit 936194f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/FSharp.Data/FSharp.Data.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
<Tailcalls>true</Tailcalls>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Net\Http.fs" />
<Compile Include="..\CommonRuntime\IO.fs" />
Expand Down
29 changes: 22 additions & 7 deletions src/Html/HtmlParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ module internal HtmlParser =
| '&' ->
assert (state.ContentLength = 0)
state.InsertionMode := InsertionMode.CharRefMode
attributeValueCharRef ['/'; '>'] attributeValueUnquoted state
attributeValueUnquotedCharRef ['/'; '>'] state
| _ -> state.ConsAttrValue(); attributeValueUnquoted state
and attributeValueUnquotedSlash state =
match state.Peek() with
Expand All @@ -713,23 +713,38 @@ module internal HtmlParser =
| '&' ->
assert (state.ContentLength = 0)
state.InsertionMode := InsertionMode.CharRefMode
attributeValueCharRef [quote] (attributeValueQuoted quote) state
attributeValueQuotedCharRef quote state
| _ -> state.ConsAttrValue(); attributeValueQuoted quote state
and attributeValueCharRef stop continuation (state:HtmlState) =
and attributeValueQuotedCharRef quote state =
match state.Peek() with
| ';' ->
state.Cons()
state.EmitToAttributeValue()
continuation state
attributeValueQuoted quote state
| TextParser.EndOfFile _ ->
state.EmitToAttributeValue()
continuation state
attributeValueQuoted quote state
| c when c = quote ->
state.EmitToAttributeValue()
attributeValueQuoted quote state
| _ ->
state.Cons()
attributeValueQuotedCharRef quote state
and attributeValueUnquotedCharRef stop state =
match state.Peek() with
| ';' ->
state.Cons()
state.EmitToAttributeValue()
attributeValueUnquoted state
| TextParser.EndOfFile _ ->
state.EmitToAttributeValue()
attributeValueUnquoted state
| c when List.exists ((=) c) stop ->
state.EmitToAttributeValue()
continuation state
attributeValueUnquoted state
| _ ->
state.Cons()
attributeValueCharRef stop continuation state
attributeValueUnquotedCharRef stop state
and afterAttributeValueQuoted state =
match state.Peek() with
| TextParser.Whitespace _ -> state.Pop(); state.NewAttribute(); afterAttributeValueQuoted state
Expand Down
13 changes: 13 additions & 0 deletions tests/FSharp.Data.Tests/HtmlParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ let ``Can handle attributes with no value``() =
]
node.Attributes() |> should equal expected

[<Test>]
let ``Can handle long html encoded attributes without StackOverflow``() =
let html =
HtmlNode.Parse (
let sb = new System.Text.StringBuilder()
sb.Append "<html><body><p attrib=\"" |> ignore
for i in 0 .. 50000 do sb.Append "&lt;br/&gt;" |> ignore
sb.Append "\">Test</p></html></body>" |> ignore
sb.ToString()
)
let result = html.Head.InnerText()
result |> should equal "Test"

[<TestCase("var r = \"</script>\"")>]
[<TestCase("var r = '</script>'")>]
[<TestCase("var r = /</g")>]
Expand Down

0 comments on commit 936194f

Please sign in to comment.