X Tutup
Skip to content

Commit c9e297d

Browse files
committed
Fix xargs.partition: win32 new string length computation
1 parent 2560280 commit c9e297d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pre_commit/xargs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ def _command_length(*cmd):
1717
full_cmd = ' '.join(cmd)
1818

1919
# win32 uses the amount of characters, more details at:
20-
# https://blogs.msdn.microsoft.com/oldnewthing/20031210-00/?p=41553/
20+
# https://github.com/pre-commit/pre-commit/pull/839
2121
if sys.platform == 'win32':
22-
return len(full_cmd)
22+
return len(full_cmd.encode('utf-16le')) // 2
2323

2424
return len(full_cmd.encode(sys.getfilesystemencoding()))
2525

tests/xargs_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_partition_limits():
5555

5656
def test_partition_limit_win32(sys_win32_mock):
5757
cmd = ('ninechars',)
58-
varargs = (u'😑' * 10,)
58+
varargs = ('😑' * 10,)
5959
with mock.patch('pre_commit.xargs.sys', sys_win32_mock):
6060
ret = xargs.partition(cmd, varargs, _max_length=20)
6161

@@ -64,7 +64,7 @@ def test_partition_limit_win32(sys_win32_mock):
6464

6565
def test_partition_limit_linux(sys_linux_mock):
6666
cmd = ('ninechars',)
67-
varargs = (u'😑' * 5,)
67+
varargs = ('😑' * 5,)
6868
with mock.patch('pre_commit.xargs.sys', sys_linux_mock):
6969
ret = xargs.partition(cmd, varargs, _max_length=30)
7070

@@ -73,7 +73,7 @@ def test_partition_limit_linux(sys_linux_mock):
7373

7474
def test_argument_too_long_with_large_unicode(sys_linux_mock):
7575
cmd = ('ninechars',)
76-
varargs = (u'😑' * 10,) # 4 bytes * 10
76+
varargs = ('😑' * 10,) # 4 bytes * 10
7777
with mock.patch('pre_commit.xargs.sys', sys_linux_mock):
7878
with pytest.raises(xargs.ArgumentTooLongError):
7979
xargs.partition(cmd, varargs, _max_length=20)

0 commit comments

Comments
 (0)
X Tutup