Mercurial > hg > orthanc-python
comparison Sources/PythonString.cpp @ 45:ee76cced46a5
Fix issue #185 (segfaults on non-UTF8 special characters in request URI)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 03 Aug 2020 18:13:10 +0200 |
parents | fd58eb5749ed |
children | 23f3099bed47 |
comparison
equal
deleted
inserted
replaced
44:2468e2f2456c | 45:ee76cced46a5 |
---|---|
19 | 19 |
20 #include "PythonString.h" | 20 #include "PythonString.h" |
21 | 21 |
22 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" | 22 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" |
23 | 23 |
24 PythonString::PythonString(PythonLock& lock, | 24 |
25 const std::string& utf8) : | 25 void PythonString::SanityCheck() |
26 string_(lock, PyUnicode_FromString(utf8.c_str())) | |
27 { | 26 { |
28 if (!string_.IsValid()) | 27 if (!string_->IsValid()) |
29 { | 28 { |
30 OrthancPlugins::LogError("Cannot create a Python string"); | 29 OrthancPlugins::LogError("Cannot create a Python string, check that the string is properly encoded using UTF-8"); |
31 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); | 30 ORTHANC_PLUGINS_THROW_EXCEPTION(InternalError); |
32 } | 31 } |
33 } | 32 } |
33 | |
34 | |
35 PythonString::PythonString(PythonLock& lock, | |
36 const std::string& utf8) | |
37 { | |
38 string_.reset(new PythonObject(lock, PyUnicode_FromString(utf8.c_str()))); | |
39 SanityCheck(); | |
40 } | |
41 | |
42 | |
43 PythonString::PythonString(PythonLock& lock, | |
44 const char* utf8) | |
45 { | |
46 if (utf8 == NULL) | |
47 { | |
48 ORTHANC_PLUGINS_THROW_EXCEPTION(NullPointer); | |
49 } | |
50 else | |
51 { | |
52 string_.reset(new PythonObject(lock, PyUnicode_FromString(utf8))); | |
53 SanityCheck(); | |
54 } | |
55 } |