diff options
author | Max Romanov <max.romanov@nginx.com> | 2018-08-06 19:16:45 +0300 |
---|---|---|
committer | Max Romanov <max.romanov@nginx.com> | 2018-08-06 19:16:45 +0300 |
commit | b021188e95380c77248d38be4aa74c1877e51683 (patch) | |
tree | 271639bd35565abb5baac2811bd5c1a98b097221 /src | |
parent | 1bb22d1e922c87d3c86c67bdce626767ee48fb5c (diff) | |
download | unit-b021188e95380c77248d38be4aa74c1877e51683.tar.gz unit-b021188e95380c77248d38be4aa74c1877e51683.tar.bz2 |
Python: decoding unicode strings as Latin1.
According to PEP 3333, header names and values should be decoded as Latin1.
Diffstat (limited to 'src')
-rw-r--r-- | src/nxt_python_wsgi.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/nxt_python_wsgi.c b/src/nxt_python_wsgi.c index c3978764..d925b33f 100644 --- a/src/nxt_python_wsgi.c +++ b/src/nxt_python_wsgi.c @@ -41,12 +41,11 @@ #if PY_MAJOR_VERSION == 3 #define NXT_PYTHON_BYTES_TYPE "bytestring" -#define PyString_FromString PyUnicode_FromString -#define PyString_FromStringAndSize PyUnicode_FromStringAndSize +#define PyString_FromStringAndSize(str, size) \ + PyUnicode_DecodeLatin1((str), (size), "strict") #else #define NXT_PYTHON_BYTES_TYPE "string" -#define PyBytes_FromString PyString_FromString #define PyBytes_FromStringAndSize PyString_FromStringAndSize #define PyBytes_Check PyString_Check #define PyBytes_GET_SIZE PyString_GET_SIZE @@ -627,7 +626,7 @@ nxt_python_create_environ(nxt_task_t *task) } - obj = PyString_FromString("http"); + obj = PyString_FromStringAndSize("http", nxt_length("http")); if (nxt_slow_path(obj == NULL)) { nxt_alert(task, @@ -805,6 +804,7 @@ nxt_python_add_sptr(nxt_python_run_ctx_t *ctx, const char *name, nxt_unit_req_error(ctx->req, "Python failed to create value string \"%.*s\"", (int) size, src); + PyErr_PrintEx(1); return NXT_UNIT_ERROR; } @@ -839,6 +839,7 @@ nxt_python_add_str(nxt_python_run_ctx_t *ctx, const char *name, nxt_unit_req_error(ctx->req, "Python failed to create value string \"%.*s\"", (int) size, str); + PyErr_PrintEx(1); return NXT_UNIT_ERROR; } @@ -1160,7 +1161,7 @@ nxt_py_input_read(nxt_py_input_t *self, PyObject *args) static PyObject * nxt_py_input_readline(nxt_py_input_t *self, PyObject *args) { - return PyBytes_FromString(""); + return PyBytes_FromStringAndSize("", 0); } |