influxdata/influxdb-client-php

\n in a field value breaks the FluxCsvParser

gmoigneu opened this issue · 2 comments

Steps to reproduce:

  1. Inject "\n" in a field
  2. Query that field (stream, raw or query have the same behavior)

Expected behavior:

The response should escape weird characters in a field and not detect them as end of line.

Actual behavior:

The parser detects "\n" as end of line:

            // Break when a new line is found
            if ($byte === "\n") {
                break;
            }

We end up with a row that has less array values than the headers. Triggering an exception on parseRecord():

$strVal = $csv[$fluxColumn->index + 1];

Specifications:

  • Client Version: 50738a7
  • InfluxDB Version: Influx Cloud as of Nov. 3rd

Hi @gmoigneu,

thanks for using our client.

I've prepared PR #101. If you would like to use dev version of client then install client via:

composer require influxdata/influxdb-client-php:fix/response-with-new-line

Regards

Oh that's amazing @bednar ! Thank you so much for this. I confirm it works flawlessly.

Without the PR, I got it to work with a regex to circumvent the issue:

|> map(fn: (r) => ({
   r with
            msg: regexp.replaceAllString(r: /(\r\n|\r|\n)/, v: r["http.msg"], t: "")
        })
    )