-
Notifications
You must be signed in to change notification settings - Fork 221
Checksyntaxwritefile #311
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
Checksyntaxwritefile #311
Conversation
...s to make sure file reading works properly
@Almenon
Almenon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. This test case fails but it is valid python syntax. It should pass.
it('should check syntax', function (done) {
PythonShell.checkSyntax("x=5#'").then(() => {
done();
})
})
I think you might be able to pipe the python code via standard in to not have to worry about string templating.
Also please move the checkSyntaxFile tests into their own describe block, as it now uses different logic
Okay, I have added changes, however I apologise I did not end up using stdin. The main reason was that I also had to add some extra functionality to make sure that command line special characters do not cause an issue. I will try to explain below:
I was thinking about your example, and your suggestion of stdin was to stop the program thinking quotation marks within the user's code are meant to couple together with the quotation marks from the compileCommand for the python code right? So, with your example, where you did:
x=5#'
That causes the quotation mark to create issues when inserted into:
${pythonPath} -c "compile('${formattedCode}', '', 'exec');"
Because now it thinks that the ' mark after compile is meant to meet with the ' mark inside the code. So, just in case, I added a test case where it uses every single special character to see which ones would be a problem:
x=5#'\"_-~!@$%&^*()=+,<.>/?{}[]\\|;:
However, while using this one, I noticed a second issue. The |, <, >, ^ and & characters are all read by the terminal and used for their own things, such as | being the pipe function, and thus if the code that the user is sending in has a singular | anywhere E.g:
x = "hi | hi2"
The command line would think we are piping x = "hi into hi2" which would also cause issues.
So, instead, I create a custom function which essentially does the formatting check for you by adding in its own \ and ^ character to make sure everything is escaped properly. I tested it with two very messy examples to make sure it is working, and I got it to work.
However, I do realise my solution is kinda scuffed and far from the cleanest, so could you perhaps add a few test cases you can think of to make sure nothing goes wrong? I am very sorry for doing a solution this scuffed, I could not think of another solution for the command line special character problem.
Changed checkSyntax to no longer write to files. Also, created separation between checkSyntax & checkSyntaxFile, as well as added more test cases & python files to ensure syntax checking is going well.