| 312 | } |
| 313 | |
| 314 | String InfluxdbCommonWriter::EscapeKeyOrTagValue(const String& str) |
| 315 | { |
| 316 | // Iterate over the key name and escape commas and spaces with a backslash |
| 317 | String result = str; |
| 318 | boost::algorithm::replace_all(result, "\"", "\\\""); |
| 319 | boost::algorithm::replace_all(result, "=", "\\="); |
| 320 | boost::algorithm::replace_all(result, ",", "\\,"); |
| 321 | boost::algorithm::replace_all(result, " ", "\\ "); |
| 322 | |
| 323 | // InfluxDB 'feature': although backslashes are allowed in keys they also act |
| 324 | // as escape sequences when followed by ',' or ' '. When your tag is like |
| 325 | // 'metric=C:\' bad things happen. Backslashes themselves cannot be escaped |
| 326 | // and through experimentation they also escape '='. To be safe we replace |
| 327 | // trailing backslashes with and underscore. |
| 328 | // See https://github.com/influxdata/influxdb/issues/8587 for more info |
| 329 | size_t length = result.GetLength(); |
| 330 | if (result[length - 1] == '\\') |
| 331 | result[length - 1] = '_'; |
| 332 | |
| 333 | return result; |
| 334 | } |
| 335 | |
| 336 | String InfluxdbCommonWriter::EscapeValue(const Value& value) |
| 337 | { |