godot-console icon indicating copy to clipboard operation
godot-console copied to clipboard

Error when single or double quote after string

Open Braboware opened this issue 2 years ago • 6 comments

I get the error Invalid operands 'String' and 'Nil' in operator '+'. when I try writing, for example, somestring' or even just '' in the console. It doesn't happen for a singular standalone single/double quote '. It also doesn't give an error for 3+ quotes '''.

It's also worth noting that if there is more than one quote after the string ex. hello'' the console will say Command `ello'` not found. culling the first char in the string, which may or may not be related.

Braboware avatar Dec 16 '21 02:12 Braboware

Could you please write your test cases in form:

Input:
Output:
Expected output:
Comment:

Comment might be optional, but generally it is good to have everything described.

quentincaffeino avatar Dec 16 '21 06:12 quentincaffeino

Yeah no problem

ID: 1
Input: '
Output: Command `'` not found.
Expected output: Command `'` not found.
Comment: Working as intended
ID: 2
Input: ''
Output: Invalid operands 'String' and 'Nil' in operator '+'.
Expected output: Command `''` not found.
Comment: Output is error shown in debugger
ID: 3
Input: '''
Output: Command `'` not found.
Expected output: Command `'''` not found.
Comment: Strange that this doesn't cause an error
ID: 4
Input: ''''
Output: Command `'` not found.
Expected output: Command `''''` not found.
Comment: Same as above
ID: 5
Input: asdf
Output: Command `asdf` not found.
Expected output: Command `asdf` not found.
Comment: Working as intended
ID: 6
Input: asdf'
Output: Invalid operands 'String' and 'Nil' in operator '+'.
Expected output: Command `asdf'` not found.
Comment: Output is error shown in debugger
ID: 7
Input: asdf''
Output: Command `sdf'` not found.
Expected output: Command `asdf''` not found.
Comment: For whatever reason the `a` in `asdf''` is culled
ID: 8
Input: hello''
Output: Command `ello'` not found.
Expected output: Command `hello''` not found.
Comment: Same as above but for `h`

Above results are the same with ", just replace all instances of ' with "

Testing other symbols:

ID: 9
Input: asdf;
Output: Command `asdf` not found.
Expected output: Command `asdf;` not found.
Comment: For whatever reason the `;` in `asdf;` is culled

Rest of common symbols:

ID: 10
Input: !
Output: Command `!` not found.
Expected output: Command `!` not found.
Comment: Working as intended
ID: 11
Input: asdf!
Output: Command `asdf!` not found.
Expected output: Command `asdf!` not found.
Comment: Working as intended

Above results are the same with @#$%^&*()-_=+[{]}\|:<,>.?/`~, just replace all instances of ! with @#$%^&*()-_=+[{]}\|:<,>.?/`~ individually

Braboware avatar Dec 16 '21 18:12 Braboware

Number 9 is definitely not an error. Reason is I'm trying to build a posix-like shell. And ; is used to separate commands unconditionally. a; b will run command a then b.

I'll have a look at other cases later when I get to pc.

quentincaffeino avatar Dec 16 '21 19:12 quentincaffeino

I'm working on this in a separate branch https://github.com/quentincaffeino/godot-console/tree/fix/command-parsing-79

NOTE: Current implementation of command parser is still the initial one I wrote thinking 'just works (tm)', but with time as I've kept expanding it functionality it became very cluttered and not very pleasant to work with. I plan to completely rewrite it.

I fixed: 2 and 4, both should produce no output as you've basically asked to run an command with empty name. I will merge those fixes shortly and post an update to godotengine asset library.

Now onto what wasn't fixed:

  1. Currently I don't really want to fix 1, 3 and 6. All of those require an ability to parse multi-line input which would be very hacky with current command parser implementation. Could you elaborate on your use case and why do you need something like asdf'?
  2. With 7 and 8 it would also make current parser even harder to work with. Basically hello, hello'', hel'lo', hel''lo and h'el'lo all mean the same command, except some have enclosed specific parts in strings but in the end all those equals to hello.

quentincaffeino avatar Dec 24 '21 15:12 quentincaffeino

I apologize for not being clear with my reasoning in the initial issue post, I got caught up in the test cases and neglected to mention why. The initial reason I came across this issue was because I slipped and hit ' then the enter key given how close the two keys are on the keyboard and it resulted in a game crash because of the Invalid operands 'String' and 'Nil' in operator '+'. error which I thought might be an issue if someone else slips. The other cases aren't really critical, but I found them while testing, so I thought they were worth mentioning.

I don't need these strange cases to work, just not crash the game which it looks like the branch fixes, so thank you for that.

Braboware avatar Dec 24 '21 17:12 Braboware

It should no longer crash. Thanks for reporting. Other cases are not strange, just very rarely used. I plan to implement them.

quentincaffeino avatar Dec 24 '21 18:12 quentincaffeino