Fix encoding of default arguments

Default arguments with escape characters in were being
over escaped. The old idl.php would first eval'd the string, then
serialized the result. The new idl.cpp just serializes the original.

We have to unencode it, then serialize.
Esse commit está contido em:
mwilliams
2013-06-28 07:47:43 -07:00
commit de Sara Golemon
commit bc52150751
3 arquivos alterados com 48 adições e 1 exclusões
@@ -0,0 +1,8 @@
<?php
function main($s) {
var_dump(wordwrap($s, 10));
}
main("hello goodbye");
@@ -0,0 +1,2 @@
string(13) "hello
goodbye"
+38 -1
Ver Arquivo
@@ -227,6 +227,42 @@ static const std::unordered_map<fbstring,fbstring> g_phpDefaults = {
{"INT_MAX", "null"},
};
static fbstring unescapeString(fbstring val) {
fbstring s = "";
for (int i = 0; i < val.size(); ) {
int ch = val[i++];
if (ch == '\\') {
if (i == val.size()) {
throw std::logic_error(
folly::format("Malformed string: '{0}'", val).str());
}
ch = val[i++];
switch (ch) {
case 'n': ch = '\n'; break;
case 'r': ch = '\r'; break;
case 't': ch = '\t'; break;
case '/':
case '"':
case '\'':
case '\\':break;
case '0':
ch = 0;
if (i == val.size() ||
(!isdigit(val[i]) && val[i] != 'x' && val[i] != 'X')) {
break;
}
// fall through
default:
throw std::logic_error(
folly::format("Malformed string: '{0}'", val).str());
break;
}
}
s += (char)ch;
}
return s;
}
/**
* From idl/base.php:get_serialized_default()
*/
@@ -275,7 +311,8 @@ fbstring PhpParam::getDefaultSerialized() const {
// Quoted string: "foo"
if ((val.size() >= 2) && (val[0] == '"') && (val[val.size()-1] == '"')) {
return phpSerialize(val.substr(1, val.size() - 2));
auto s = unescapeString(val.substr(1, val.size() - 2));
return phpSerialize(s);
}
// Integers and Floats