Accept only the system default encoding when converting Python

strings to CF strings. Fixes 682215.
This commit is contained in:
Jack Jansen 2003-03-03 13:12:59 +00:00
parent f008998668
commit d505cab5b3
3 changed files with 11 additions and 8 deletions

View File

@ -1458,7 +1458,7 @@ int CFStringRefObj_Convert(PyObject *v, CFStringRef *p_itself)
if (v == Py_None) { *p_itself = NULL; return 1; }
if (PyString_Check(v)) {
char *cStr = PyString_AsString(v);
*p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, 0);
*p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, kCFStringEncodingASCII);
return 1;
}
if (PyUnicode_Check(v)) {

View File

@ -359,8 +359,10 @@ class CFStringRefObjectDefinition(MyGlobalObjectDefinition):
Out("""
if (v == Py_None) { *p_itself = NULL; return 1; }
if (PyString_Check(v)) {
char *cStr = PyString_AsString(v);
*p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, 0);
char *cStr;
if (!PyArg_Parse(v, "et", "ascii", &cStr))
return NULL;
*p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, kCFStringEncodingASCII);
return 1;
}
if (PyUnicode_Check(v)) {

View File

@ -292,8 +292,9 @@ PyCF_Python2CF_string(PyObject *src, CFStringRef *dst) {
UniChar *unichars;
if (PyString_Check(src)) {
if ((chars = PyString_AsString(src)) == NULL ) goto err;
*dst = CFStringCreateWithCString((CFAllocatorRef)NULL, chars, 0);
if (!PyArg_Parse(src, "es", NULL, &chars))
return NULL; /* This error is more descriptive than the general one below */
*dst = CFStringCreateWithCString((CFAllocatorRef)NULL, chars, kCFStringEncodingASCII);
return 1;
}
if (PyUnicode_Check(src)) {