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

Not escaping multiline strings correctly #1

Open
myplacedk opened this issue Feb 5, 2015 · 8 comments
Open

Not escaping multiline strings correctly #1

myplacedk opened this issue Feb 5, 2015 · 8 comments
Assignees

Comments

@myplacedk
Copy link

When I have a multiline string, "Save to ESP" fails. Example:

print([[Hello
World]])

I can execute it, but when I save it I get this:

> SENT: file.remove("delme.lua")
SENT: file.open("delme.lua","w")
SENT: file.writeline([[print([[Hello]])
SENT: file.writeline([[World]])]])
SENT: file.close()
file.remove("delme.lua")
> file.open("delme.lua","w")
> file.writeline([[print([[Hello]])
stdin:1: nesting of [[...]] is deprecated near '['
> file.writeline([[World]])]])
stdin:1: unexpected symbol near ']'
> file.close()

I think the problem is in https://github.com/hwiguna/g33k/blob/master/ArduinoProjects/Windows/ESP8266_Related/LuaUploader/SerialPort/Form1.cs line 211:

stringBuilder.AppendLine("file.writeline([[" + line + "]])");

You may want to check if there's anything else that should be escaped.

@hwiguna
Copy link
Owner

hwiguna commented Feb 6, 2015

myplacedk, thanks for reporting that. I'm a lua n00b, is that a realistic scenario? I've always used double quotes for strings: print("Hello World") or if you want the line break, then print("Hello\r\nWorld")
If we need to escape the square brackets, what's the syntax? Thanks again!

@myplacedk
Copy link
Author

It's a very realistic scenario. I've also had the problem with a line like this:

      h = b[1] * 256 + b[2]

Which becomes...

file.writeline([[h = b[1] * 256 + b[2]]])

...and the interpreter thinks there's an extra ] in the end.

I'm a Lua newbie myself, but I think a better solution may be to use single-quotes, and make sure that all single quotes and backslashes gets escaped with a backslash.

print('This is a test\twith tabs')

=>

file.writeline('print(\'This is a test\\twith tabs\')')

@hwiguna
Copy link
Owner

hwiguna commented Feb 6, 2015

Good point!
I should be able to work on this this weekend. If you like, feel free to
fix it and submit a pull request so you'll get proper credit for finding
and fixing the bug. :-)

On Fri, Feb 6, 2015 at 7:32 AM, Niels Ulrik Andersen <
[email protected]> wrote:

It's a very realistic scenario. I've also had the problem with a line like
this:

  h = b[1] * 256 + b[2]

Which becomes...

file.writeline([[h = b[1] * 256 + b[2]]])

...and the interpreter thinks there's an extra ] in the end.

I'm a Lua newbie myself, but I think a better solution may be to use
single-quotes, and make sure that all single quotes and backslashes gets
escaped with a backslash.

print('This is a test\twith tabs')

=>

file.writeline('print('This is a test\twith tabs')')


Reply to this email directly or view it on GitHub
#1 (comment).

@myplacedk
Copy link
Author

Sorry, I'm not a C# developer. If I didn't have to set up a development environment to test my fix, I'd probably have fixed it myself. :)

@hwiguna hwiguna self-assigned this Feb 9, 2015
@hwiguna
Copy link
Owner

hwiguna commented Feb 9, 2015

@myplacedk
Copy link
Author

I don't have an esp8266 with me, but this looks okay to me.

Input:

a = [[ This is
a test]]
b = a[0]
c = 'More test'
d = 'Here\'s even more'`

1.0.2.2:

file.writeline([[a = [[ This is]])
file.writeline([[a test]]]]) -- Syntax error
file.writeline([[b = a[0]]]) -- Syntax error
file.writeline([[c = 'More test']])
file.writeline([[d = 'Here\'s even more']])

1.0.2.3:

file.writeline('a = [[ This is')
file.writeline('a test]]')
file.writeline('b = a[0]')
file.writeline('c = \'More test\'')
file.writeline('d = \'Here\\\'s even more\'')
-- No syntax errors, yay!

@hwiguna
Copy link
Owner

hwiguna commented Feb 10, 2015

Niels,
I've pulled the fix into the master branch. Thank you VERY MUCH for
improving LUA Uploader!!!

On Mon, Feb 9, 2015 at 2:58 AM, Niels Ulrik Andersen <
[email protected]> wrote:

I don't have an esp8266 with me, but this looks okay with me.

Input:

a = [[ This isa test]]
b = a[0]
c = 'More test'
d = 'Here's even more'`

1.0.2.2:

file.writeline([[a = [[ This is]])
file.writeline([[a test]]]]) -- Syntax error
file.writeline([[b = a[0]]]) -- Syntax error
file.writeline([[c = 'More test']])
file.writeline([[d = 'Here's even more']])

1.0.2.3:

file.writeline('a = [[ This is')
file.writeline('a test]]')
file.writeline('b = a[0]')
file.writeline('c = 'More test'')
file.writeline('d = 'Here\'s even more'')-- No syntax errors, yay!


Reply to this email directly or view it on GitHub
#1 (comment).

@thakshak
Copy link

i still have problem with '\n' in buf="textBox.value.split('\n');"
it shows
stdin:1: unexpected symbol near ''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants