FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Checksyntaxwritefile by PlakxD · Pull Request #311 · extrabacon/python-shell · GitHub

Repository navigation

Checksyntaxwritefile - #311

Open
PlakxD wants to merge 6 commits into
extrabacon:masterfrom
PlakxD:checksyntaxwritefile
Open

PlakxD wants to merge 6 commits into
extrabacon:masterfrom
PlakxD:checksyntaxwritefile

Conversation

PlakxD commented Sep 13, 2024

Copy link
Copy Markdown

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.

Almenon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

PlakxD commented Sep 26, 2024 •
edited
Loading

Copy link
Copy Markdown
Author

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.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL