-
Notifications
You must be signed in to change notification settings - Fork 8
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
Reworked player-cli's parse_dockerfile_cmd-Function #7
Reworked player-cli's parse_dockerfile_cmd-Function #7
Conversation
Thank you for your contribution, this looks awesome! Might take a while tho until I can merge it, I'm a little busy right now. |
This looks like a really nice speed up and readability update :) Could we just change the I also tried CMD [ "python", "script.py", "--blacklist-chars", "\"+'\t" ] It is a trade-off for speed however, depends on the wanted use-cases. Also, what do you think about multi-whitespace regex |
Thanks for the feedback guys. @DaClemens: Take your time, it's just a readability improvement. @aljazmedic: Regarding the special characters: CHECK_FOR_CMD = re.compile(r'CMD\s+\[\s+(.+)\s+\]')
def parse_dockerfile_cmd_new(content: str) -> list[str] | None:
matches = CHECK_FOR_CMD.findall(content)
if matches:
ret_arguments = []
for argument in matches[-1].split(","):
ret_arguments.append(
# Partition the string on the first "
argument.partition("\"")[2]\
# and on the last "
.rpartition("\"")[0]
)
return ret_arguments
return None The performance isn't too bad after all.
|
The partition trick is really neat! But I think there are still some (really really rare) edge cases, e.g. My last iteration for regex is currently: |
Since I'm still on vacation, I'll just leave two things to keep in mind here:
|
by the looks, this shouldn't interfere with my recently published updates, but would you mind to rebase / update it anyways? |
…rework_dockerfile_parsing
Ups, I accidentally closed the PR while updating it. |
I found a small issue with the previously used regex and added a docstring. |
Thank you very much! |
Reordered Imports, reworked parse_dockerfile_cmd, added a docstring (incl. doctests)
Reordered Imports, reworked parse_dockerfile_cmd, added a docstring (incl. doctests)
This pull-requests reworks the
parse_dockerfile_cmd
-Function in theplayer-cli
.This was mainly done to improve the readability of the code. A nice side-effect that the runtime of the code improved.
For the performance test I used the template for the python exploit.
Please see the following code for the performance test.
In my opinion, alphabetically sorted imports also increase the readability. Thats why I also sorted them.
Any feedback is appreciated.