blackd: fix mishandling of single character input (#3558)
This commit is contained in:
parent
df50fee7fd
commit
8daa64a2e1
@ -45,6 +45,8 @@
|
|||||||
|
|
||||||
<!-- Changes to blackd -->
|
<!-- Changes to blackd -->
|
||||||
|
|
||||||
|
- Fix an issue in `blackd` with single character input (#3558)
|
||||||
|
|
||||||
### Integrations
|
### Integrations
|
||||||
|
|
||||||
<!-- For example, Docker, GitHub Actions, pre-commit, editors -->
|
<!-- For example, Docker, GitHub Actions, pre-commit, editors -->
|
||||||
|
@ -152,7 +152,8 @@ async def handle(request: web.Request, executor: Executor) -> web.Response:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Preserve CRLF line endings
|
# Preserve CRLF line endings
|
||||||
if req_str[req_str.find("\n") - 1] == "\r":
|
nl = req_str.find("\n")
|
||||||
|
if nl > 0 and req_str[nl - 1] == "\r":
|
||||||
formatted_str = formatted_str.replace("\n", "\r\n")
|
formatted_str = formatted_str.replace("\n", "\r\n")
|
||||||
# If, after swapping line endings, nothing changed, then say so
|
# If, after swapping line endings, nothing changed, then say so
|
||||||
if formatted_str == req_str:
|
if formatted_str == req_str:
|
||||||
|
@ -240,3 +240,9 @@ async def test_normalizes_line_endings(self) -> None:
|
|||||||
response = await self.client.post("/", data=data)
|
response = await self.client.post("/", data=data)
|
||||||
self.assertEqual(await response.text(), expected)
|
self.assertEqual(await response.text(), expected)
|
||||||
self.assertEqual(response.status, 200)
|
self.assertEqual(response.status, 200)
|
||||||
|
|
||||||
|
@unittest_run_loop
|
||||||
|
async def test_single_character(self) -> None:
|
||||||
|
response = await self.client.post("/", data="1")
|
||||||
|
self.assertEqual(await response.text(), "1\n")
|
||||||
|
self.assertEqual(response.status, 200)
|
||||||
|
Loading…
Reference in New Issue
Block a user