Address Daira's comments
This commit is contained in:
parent
519713d32e
commit
0b431fbdb5
|
@ -150,6 +150,11 @@ BOOST_AUTO_TEST_CASE(util_ParseTorReplyMapping)
|
||||||
{"Octals", "\1a\11\17\1" "881\377\37" "8400"},
|
{"Octals", "\1a\11\17\1" "881\377\37" "8400"},
|
||||||
{"Final", "Check"},
|
{"Final", "Check"},
|
||||||
});
|
});
|
||||||
|
CheckParseTorReplyMapping(
|
||||||
|
"Valid=Mapping Escaped=\"Escape\\\\\"", {
|
||||||
|
{"Valid", "Mapping"},
|
||||||
|
{"Escaped", "Escape\\"},
|
||||||
|
});
|
||||||
CheckParseTorReplyMapping(
|
CheckParseTorReplyMapping(
|
||||||
"Valid=Mapping Bare=\"Escape\\\"", {});
|
"Valid=Mapping Bare=\"Escape\\\"", {});
|
||||||
CheckParseTorReplyMapping(
|
CheckParseTorReplyMapping(
|
||||||
|
|
|
@ -290,7 +290,8 @@ static std::map<std::string,std::string> ParseTorReplyMapping(const std::string
|
||||||
++ptr; // skip opening '"'
|
++ptr; // skip opening '"'
|
||||||
bool escape_next = false;
|
bool escape_next = false;
|
||||||
while (ptr < s.size() && (escape_next || s[ptr] != '"')) {
|
while (ptr < s.size() && (escape_next || s[ptr] != '"')) {
|
||||||
escape_next = (s[ptr] == '\\');
|
// Repeated backslashes must be interpreted as pairs
|
||||||
|
escape_next = (s[ptr] == '\\' && !escape_next);
|
||||||
value.push_back(s[ptr]);
|
value.push_back(s[ptr]);
|
||||||
++ptr;
|
++ptr;
|
||||||
}
|
}
|
||||||
|
@ -298,7 +299,7 @@ static std::map<std::string,std::string> ParseTorReplyMapping(const std::string
|
||||||
return std::map<std::string,std::string>();
|
return std::map<std::string,std::string>();
|
||||||
++ptr; // skip closing '"'
|
++ptr; // skip closing '"'
|
||||||
/**
|
/**
|
||||||
* Escape value. Per https://spec.torproject.org/control-spec section 2.1.1:
|
* Unescape value. Per https://spec.torproject.org/control-spec section 2.1.1:
|
||||||
*
|
*
|
||||||
* For future-proofing, controller implementors MAY use the following
|
* For future-proofing, controller implementors MAY use the following
|
||||||
* rules to be compatible with buggy Tor implementations and with
|
* rules to be compatible with buggy Tor implementations and with
|
||||||
|
@ -310,10 +311,10 @@ static std::map<std::string,std::string> ParseTorReplyMapping(const std::string
|
||||||
std::string escaped_value;
|
std::string escaped_value;
|
||||||
for (size_t i = 0; i < value.size(); ++i) {
|
for (size_t i = 0; i < value.size(); ++i) {
|
||||||
if (value[i] == '\\') {
|
if (value[i] == '\\') {
|
||||||
// This will always be valid, because if the final character
|
// This will always be valid, because if the QuotedString
|
||||||
// in the QuotedString was a \ then the parser would already
|
// ended in an odd number of backslashes, then the parser
|
||||||
// have returned above, due to a missing terminating
|
// would already have returned above, due to a missing
|
||||||
// double-quote.
|
// terminating double-quote.
|
||||||
++i;
|
++i;
|
||||||
if (value[i] == 'n') {
|
if (value[i] == 'n') {
|
||||||
escaped_value.push_back('\n');
|
escaped_value.push_back('\n');
|
||||||
|
|
Loading…
Reference in New Issue