mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Ensure no trailing NULLs in result of file_association()
This commit is contained in:
parent
000bb4c89e
commit
1a1db4d1f8
@ -24,7 +24,9 @@ class TestWinutil(unittest.TestCase):
|
||||
self.winutil.add_to_recent_docs(path, 'some-app-uid')
|
||||
|
||||
def test_file_association(self):
|
||||
self.assertIn('notepad.exe', self.winutil.file_association('.txt'))
|
||||
q = self.winutil.file_association('.txt')
|
||||
self.assertIn('notepad.exe', q.lower())
|
||||
self.assertNotIn('\0', q)
|
||||
self.assertIsNone(self.winutil.file_association('.mkjsfks'))
|
||||
|
||||
def test_special_folder_path(self):
|
||||
|
@ -68,8 +68,8 @@ file_association(PyObject *self, PyObject *args) {
|
||||
if (!PyArg_ParseTuple(args, "O&", py_to_wchar, &ext)) return NULL;
|
||||
HRESULT hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, ext, NULL, buf, &sz);
|
||||
free_wchar_buffer(&ext);
|
||||
if (!SUCCEEDED(hr)) Py_RETURN_NONE;
|
||||
return Py_BuildValue("u#", buf, (int)sz);
|
||||
if (!SUCCEEDED(hr) || sz < 1) Py_RETURN_NONE;
|
||||
return Py_BuildValue("u", buf);
|
||||
}
|
||||
|
||||
PyObject *
|
||||
|
Loading…
x
Reference in New Issue
Block a user