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

[moonsharp] Unescaped control string error when using decode() and - is in a string #37

Open
TheCheddarCheese opened this issue Nov 10, 2023 · 5 comments

Comments

@TheCheddarCheese
Copy link

for example:
lunajson.decode('{"file0001.png":[0, 0]}') works
but lunajson.decode('{"file-0001.png":[0, 0]}') throws an error
billede

if this is a thing with json then please forgive me for being stupid

@tst2005
Copy link
Contributor

tst2005 commented Nov 24, 2023

I'm not reproducing your problem...

  • Do you get the same issue with any value ?
  • lunajson.decode('{"foo-bar":"buz"}') fail ?

@TheCheddarCheese
Copy link
Author

yeah
forgot to mention the program uses moonsharp, so maybe it's just that

@tst2005
Copy link
Contributor

tst2005 commented Dec 7, 2023

Oh yes, there is probably a difference of behavior or implementation somewhere...

The error message comes from lunajson :
see https://github.com/grafi-tt/lunajson/blob/master/src/lunajson/decoder.lua#L341
but the error is raised for a reason.
We need more information...

Can you change the line 341 of lunajson.decode to replace

decode_error("unescaped control string")

by

decode_error("unescaped control string" .. " ; str=" .. tostring(str) .. " ; f_str_ctrl_pat=" .. tostring(f_str_ctrl_pat) .. " ;" )

The error will show the value of str and f_str_ctrl_pat ... useful to understand/reproduce the issue.

@grafi-tt
Copy link
Owner

Thank you for reporting the issue. Many thanks to @tst2005 too.

Could you report lua version? Perhaps - in a pattern is misinterpreted by some lua implementation.

See

if _VERSION == "Lua 5.1" then
-- use the cluttered pattern because lua 5.1 does not handle \0 in a pattern correctly
f_str_ctrl_pat = '[^\32-\255]'
else
f_str_ctrl_pat = '[\0-\31]'
end

@grafi-tt
Copy link
Owner

OK maybe this issue is relevant. moonsharp-devs/moonsharp#29

Could you modify the version check and test again? If it works fine, I'll merge a PR.

@grafi-tt grafi-tt changed the title Unescaped control string error when using decode() and - is in a string [moonscript] Unescaped control string error when using decode() and - is in a string Mar 14, 2024
@grafi-tt grafi-tt changed the title [moonscript] Unescaped control string error when using decode() and - is in a string [moonsharp] Unescaped control string error when using decode() and - is in a string Mar 14, 2024
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