From 18d654b39fecc7d3efd6e1f1828a38f8d3b08886 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sun, 20 Dec 2015 02:19:11 -0800 Subject: [PATCH] Fix quote when stringifying C/Objective-C strings. --- Execute.cpp | 2 +- Library.cpp | 23 ++++++++++++++--------- ObjectiveC/Library.mm | 2 +- cycript.hpp | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Execute.cpp b/Execute.cpp index 2e02b28..1a3a2df 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -1611,7 +1611,7 @@ static JSValueRef CString_callAsFunction_toCYON(JSContextRef context, JSObjectRe const char *string(static_cast(internal->value_)); std::ostringstream str; str << "&"; - CYStringify(str, string, strlen(string)); + CYStringify(str, string, strlen(string), true); std::string value(str.str()); return CYCastJSValue(context, CYJSString(CYUTF8String(value.c_str(), value.size()))); } CYCatch(NULL) } diff --git a/Library.cpp b/Library.cpp index aa85e81..ac9d8b0 100644 --- a/Library.cpp +++ b/Library.cpp @@ -103,15 +103,20 @@ bool CYGetOffset(const char *value, ssize_t &index) { } /* }}} */ /* JavaScript *ify {{{ */ -void CYStringify(std::ostringstream &str, const char *data, size_t size) { - unsigned quot(0), apos(0); - for (const char *value(data), *end(data + size); value != end; ++value) - if (*value == '"') - ++quot; - else if (*value == '\'') - ++apos; - - bool single(quot > apos); +void CYStringify(std::ostringstream &str, const char *data, size_t size, bool c) { + bool single; + if (c) + single = false; + else { + unsigned quot(0), apos(0); + for (const char *value(data), *end(data + size); value != end; ++value) + if (*value == '"') + ++quot; + else if (*value == '\'') + ++apos; + + single = quot > apos; + } str << (single ? '\'' : '"'); diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index 1147dcc..ec80665 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -1149,7 +1149,7 @@ NSObject *CYCopyNSObject(CYPool &pool, JSContextRef context, JSValueRef value) { if (!objective) str << '@'; CYUTF8String string(CYCastUTF8String(self)); - CYStringify(str, string.data, string.size); + CYStringify(str, string.data, string.size, true); std::string value(str.str()); return CYCastNSString(NULL, CYUTF8String(value.c_str(), value.size())); } diff --git a/cycript.hpp b/cycript.hpp index a70cd94..30010f4 100644 --- a/cycript.hpp +++ b/cycript.hpp @@ -33,7 +33,7 @@ bool CYRecvAll_(int socket, uint8_t *data, size_t size); bool CYSendAll_(int socket, const uint8_t *data, size_t size); void CYNumerify(std::ostringstream &str, double value); -void CYStringify(std::ostringstream &str, const char *data, size_t size); +void CYStringify(std::ostringstream &str, const char *data, size_t size, bool c = false); double CYCastDouble(const char *value, size_t size); double CYCastDouble(const char *value); -- 2.45.2