X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/27d7ea43eb127cc5189a724a7d194d94ba312861..0359b85b5800dd77f8f1cfaa88ca8ab8215df685:/src/blackd/__init__.py diff --git a/src/blackd/__init__.py b/src/blackd/__init__.py index e52a991..6bbc7c5 100644 --- a/src/blackd/__init__.py +++ b/src/blackd/__init__.py @@ -133,6 +133,13 @@ async def handle(request: web.Request, executor: Executor) -> web.Response: executor, partial(black.format_file_contents, req_str, fast=fast, mode=mode) ) + # Preserve CRLF line endings + if req_str[req_str.find("\n") - 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 + # Only output the diff in the HTTP response only_diff = bool(request.headers.get(DIFF_HEADER, False)) if only_diff: