avast / avast/pytest-docker

Insufficient removal of control characters on windows with cmd.exe as shell

Open
#82 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
489
Forks
77
PR merge metrics
No merged PRs in 30d

Description

Affected Line https://github.com/avast/pytest-docker/blob/567fa091a0d8ccf4ac2e8897c1ccecf08774125c/src/pytest_docker/plugin.py#L79
`endpoint = output.strip().decode("utf-8")`
Affected Version: at least since 0.10.3

I use PyCharm on Windows 10 to debug my pytest test cases. Starting the conatiners the above line is executed to to resolve a port for a service.

`output = self._docker_compose.execute("port %s %d" % (service, container_port))` results to b'0.0.0.0:12347\r\n\x1b[0m'. No control character is removed. Hence, `output.strip().decode("utf-8")` result to s string including the control characters.

Some lines later (L86) `if len(endpoint.split("\n")) > 1:` does not support windows line endings.

On Linux or Git Bash for Windows, there is no problem.

My fix for that. Please check this solution:

```
endpoint = endpoint.replace("\r",'') # add support for windows line ending
if len(endpoint.split("\n")) > 1:
endpoint = endpoint.split("\n")[-1] # index -1 is also wrong for me because it results to '\x1b[0m'. Maybe use 0 or -2
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/pytest_docker/plugin.py at the affected line 79 and trace the endpoint parsing through line 86. Reproduce the Windows cmd.exe output shown in the issue, then verify that control characters and Windows line endings are handled without leaving escape characters in the resolved endpoint.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
devops
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.