Skip to content

Commit

Permalink
Fix error in hooks when parsing incomplete x. (#385)
Browse files Browse the repository at this point in the history
Also add another fuzzing tool
  • Loading branch information
c42f committed Nov 7, 2023
1 parent e3df852 commit 1351d70
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/hooks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ function _has_nested_error(ex)
else
return any(_has_nested_error(e) for e in ex.args)
end
elseif ex isa QuoteNode
return _has_nested_error(ex.value)
else
return false
end
Expand Down
4 changes: 4 additions & 0 deletions test/fuzz_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,10 @@ function product_token_fuzz(tokens, N)
(join(ts) for ts in Iterators.product([tokens for _ in 1:N]...))
end

function random_token_fuzz(tokens, ntokens, ntries)
(join(rand(tokens, ntokens)) for _ in 1:ntries)
end

"""
Fuzz test parser against randomly generated binary strings
"""
Expand Down
4 changes: 4 additions & 0 deletions test/hooks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ end
LineNumberNode(4, "somefile"),
]
@test Meta.isexpr(ex.args[6], :error)

ex = JuliaSyntax.core_parser_hook("x.", "somefile", 0, 0, :all)[1]
@test ex.head == :toplevel
@test ex.args[2].head == :incomplete
end

@testset "enable_in_core!" begin
Expand Down

0 comments on commit 1351d70

Please sign in to comment.