Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unterminated (single-line) string literal does not raise an error #73

Closed
berbun opened this issue Oct 24, 2019 · 4 comments
Closed

Unterminated (single-line) string literal does not raise an error #73

berbun opened this issue Oct 24, 2019 · 4 comments
Assignees
Labels
incorrect parsing Valid Lua code fails to parse, is parsed incorrectly, or invalid Lua code is accepted
Milestone

Comments

@berbun
Copy link

berbun commented Oct 24, 2019

Samples

luaparse.parse("s='");
luaparse.parse('s="');
luaparse.parse("s='\\\n");
luaparse.parse('s="\\\n');

(unterminated multi-line string seems to raise an exception unless it is run on command-line.)

From command-line

>luaparse -c "local s=\""
{"type":"Chunk","body":[{"type":"LocalStatement","variables":[{"type":"Identifier","name":"s"}],"init":[{"type":"StringLiteral","value":"","raw":"\""}]}],"comments":[]}

>luaparse -c "local s='"
{"type":"Chunk","body":[{"type":"LocalStatement","variables":[{"type":"Identifier","name":"s"}],"init":[{"type":"StringLiteral","value":"","raw":"'"}]}],"comments":[]}

>luaparse -c "local s=[["
{"type":"Chunk","body":[{"type":"LocalStatement","variables":[{"type":"Identifier","name":"s"}],"init":[{"type":"StringLiteral","value":"","raw":"[["}]}],"comments":[]}

Rundown

The path goes down to
parsePrimaryExpression() which calls next() here, which calls lex(), appending EOF token.

@fstirlitz fstirlitz self-assigned this Oct 24, 2019
@fstirlitz fstirlitz added this to the 0.3 milestone Oct 24, 2019
@fstirlitz fstirlitz added the incorrect parsing Valid Lua code fails to parse, is parsed incorrectly, or invalid Lua code is accepted label Oct 24, 2019
@fstirlitz
Copy link
Owner

The multi-line strings bug appears probably because you're running an old version from the command line. Check your PATH.

The other two I can confirm. I was pretty sure this was tested already, but apparently not strictly enough. Should be easy to fix, though.

@berbun
Copy link
Author

berbun commented Oct 24, 2019

I installed it via npm i -g luaparse, the luaparse --v says "luaparse v0.2.1".

The other two I can confirm.

btw I added 2 more cases up there, just in case since you haven't noticed.

For the sake of completeness, the following is valid in LuaJIT (not sure about vanilla Lua):

s="1\
2"print(string.byte(s,1,#s))

Outputs:

49 10 50

By using \ followed by newline (CR/LR or both), it is substituted with \n (LF) char.

@fstirlitz
Copy link
Owner

Yes, the version available from npm is not fixed. Latest git master at least handles multi-line strings correctly.

@fstirlitz
Copy link
Owner

fstirlitz commented Oct 24, 2019

Fixed in 28afaef d49b641 c3e11ee.

(That should teach me not to work on several things at once.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
incorrect parsing Valid Lua code fails to parse, is parsed incorrectly, or invalid Lua code is accepted
Projects
None yet
Development

No branches or pull requests

2 participants