aemkei / jsfuck

Write any JavaScript with 6 Characters: []()!+
jsfuck.com
Do What The F*ck You Want To Public License
8.12k stars 672 forks source link

Encoding undefined #68

Closed voliva closed 5 years ago

voliva commented 7 years ago

When trying to encode the string "undefined", it encodes it as [[][[]]]+[]

However, this is wrong, because [[][[]]] evaluates to [undefined] and when converting this to string by +[], then it results in ""

I think it should either get the first element by [+[]] and then converting to string, so the result should be: [[][[]]][+[]]+[], or better yet, not wrap undefined into an array, by getting it to [][[]]+[]

EvanCarroll commented 6 years ago

This is in a fact an issue. I believe the only way to solve this problem is to become context-aware. Perhaps we could rewrite and piggy back on Acorn or Espree?

This would be massively slower, but it is the right way to do it. We should generate bytecode from the AST.

aemkei commented 5 years ago

Thanks to @hazzik for the fix!