Commit 1af19b2a authored by xiafan_linux's avatar xiafan_linux

fix the bug of strRepr. Now single quote is escaped correctly

parent 4da376b5
...@@ -148,7 +148,7 @@ static void _thread_context_dump(int signum, siginfo_t* info, void* _context) { ...@@ -148,7 +148,7 @@ static void _thread_context_dump(int signum, siginfo_t* info, void* _context) {
if (VERBOSITY() >= 2) { if (VERBOSITY() >= 2) {
printf("in thread_context_dump, tid=%d\n", tid); printf("in thread_context_dump, tid=%d\n", tid);
printf("%p %p %p\n", context, &context, context->uc_mcontext.fpregs); printf("%p %p %p\n", context, &context, context->uc_mcontext.fpregs);
printf("old rip: 0x%lx\n", context->uc_mcontext.gregs[REG_RIP]); printf("old rip: 0x%llx\n", context->uc_mcontext.gregs[REG_RIP]);
} }
pushThreadState(tid, context); pushThreadState(tid, context);
......
...@@ -237,10 +237,14 @@ extern "C" Box* strRepr(BoxedString* self) { ...@@ -237,10 +237,14 @@ extern "C" Box* strRepr(BoxedString* self) {
std::ostringstream os(""); std::ostringstream os("");
const std::string& s = self->s; const std::string& s = self->s;
os << '\''; char quote = '\'';
if (s.find('\'', 0) != std::string::npos && s.find('\"', 0) == std::string::npos) {
quote = '\"';
}
os << quote;
for (int i = 0; i < s.size(); i++) { for (int i = 0; i < s.size(); i++) {
char c = s[i]; char c = s[i];
if (!_needs_escaping[c & 0xff]) { if ((c == '\'' && quote == '\"') || !_needs_escaping[c & 0xff]) {
os << c; os << c;
} else { } else {
char special = 0; char special = 0;
...@@ -275,7 +279,7 @@ extern "C" Box* strRepr(BoxedString* self) { ...@@ -275,7 +279,7 @@ extern "C" Box* strRepr(BoxedString* self) {
} }
} }
} }
os << '\''; os << quote;
return boxString(os.str()); return boxString(os.str());
} }
......
a=1
try:
a.b
except AttributeError, e:
print repr(e)
print repr("both\'\"quotes")
print repr("single\'quote")
print repr("double\"quote")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment