]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

blackd: fix mishandling of single character input (#3558)
authorKotlinIsland <65446343+KotlinIsland@users.noreply.github.com>
Thu, 7 Sep 2023 07:11:50 +0000 (17:11 +1000)
committerGitHub <noreply@github.com>
Thu, 7 Sep 2023 07:11:50 +0000 (00:11 -0700)
CHANGES.md
src/blackd/__init__.py
tests/test_blackd.py

index 2168c1b90ce0b0b9a1e4214746af57a3f7483045..af9fc490acf75359ebb2165e9b567e523c03c9ed 100644 (file)
@@ -45,6 +45,8 @@
 
 <!-- Changes to blackd -->
 
+- Fix an issue in `blackd` with single character input (#3558)
+
 ### Integrations
 
 <!-- For example, Docker, GitHub Actions, pre-commit, editors -->
index 4f2d87d0fca2bb310275c8c0a27bf160f69098df..6b0f3d33295163a2810676d773ed2ee35691be3f 100644 (file)
@@ -152,7 +152,8 @@ 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:
index 325bd7dd5aaf6f5a4483c0b53375a22e78028dad..dd2126e6bc24d97473c89153a3043af2f3f9a024 100644 (file)
@@ -240,3 +240,9 @@ class BlackDTestCase(AioHTTPTestCase):  # type: ignore[misc]
             response = await self.client.post("/", data=data)
             self.assertEqual(await response.text(), expected)
             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)