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')
|
self.winutil.add_to_recent_docs(path, 'some-app-uid')
|
||||||
|
|
||||||
def test_file_association(self):
|
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'))
|
self.assertIsNone(self.winutil.file_association('.mkjsfks'))
|
||||||
|
|
||||||
def test_special_folder_path(self):
|
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;
|
if (!PyArg_ParseTuple(args, "O&", py_to_wchar, &ext)) return NULL;
|
||||||
HRESULT hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, ext, NULL, buf, &sz);
|
HRESULT hr = AssocQueryStringW(0, ASSOCSTR_EXECUTABLE, ext, NULL, buf, &sz);
|
||||||
free_wchar_buffer(&ext);
|
free_wchar_buffer(&ext);
|
||||||
if (!SUCCEEDED(hr)) Py_RETURN_NONE;
|
if (!SUCCEEDED(hr) || sz < 1) Py_RETURN_NONE;
|
||||||
return Py_BuildValue("u#", buf, (int)sz);
|
return Py_BuildValue("u", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
|
Loading…
x
Reference in New Issue
Block a user