JuliaLang / JuliaSyntax.jl

The Julia compiler frontend
Other
274 stars 33 forks source link

Disallow unbalanced bidirectional unicode in strings and comments #242

Closed c42f closed 1 year ago

c42f commented 1 year ago

The reference parser disallows bidirectional formatting to prevent certain types of malicious code. From Julia's test/syntax.jl:

@test_throws ParseError Meta.parse("""
function checkUserAccess(u::User)
    if u.accessLevel != "user\u202e \u2066# users are not allowed\u2069\u2066"
        return true
    end
    return false
end
""")

@test_throws ParseError Meta.parse("""
function checkUserAccess(u::User)
    #=\u202e \u2066if (u.isAdmin)\u2069 \u2066 begin admins only =#
        return true
    #= end admin only \u202e \u2066end\u2069 \u2066=#
    return false
end
""")

This needs to be fixed in the tokenizer

See also the fix in the reference parser: https://github.com/JuliaLang/julia/pull/42918