abap34/almo

エスケープの動作がおかしい

Opened this issue · 0 comments

dot 言語や jsonの出力に使うために以下のようなエスケープを行ってくれる関数を使っている。

almo/src/utils.hpp

Lines 179 to 192 in a512df9

// 文字列を受け取り、ダブルクオーテーションや改行などをエスケープする
// https://stackoverflow.com/questions/7724448/simple-json-string-escape-for-c
std::string escape(const std::string &s) {
std::ostringstream o;
for (auto c = s.cbegin(); c != s.cend(); c++) {
if (*c == '"' || *c == '\\' || ('\x00' <= *c && *c <= '\x1f')) {
o << "\\u"
<< std::hex << std::setw(4) << std::setfill('0') << static_cast<int>(*c);
} else {
o << *c;
}
}
return o.str();
}

しかし、{, }, |, >, < がエスケープ対象から漏れているため、dot言語の出力が崩れる場合がある。修正が必要