Skip to content

Commit

Permalink
blackd: fix issue for mishandling single character input
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland committed Feb 9, 2023
1 parent 9c8464c commit 1ebb99d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/blackd/__init__.py
Expand Up @@ -146,11 +146,13 @@ async def handle(request: web.Request, executor: Executor) -> web.Response:
)

# 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")
# If, after swapping line endings, nothing changed, then say so
if formatted_str == req_str:
raise black.NothingChanged
del nl

# Put the source first line back
req_str = header + req_str
Expand Down

0 comments on commit 1ebb99d

Please sign in to comment.