influxdata / influxdb-client-php

InfluxDB (v2+) Client Library for PHP
https://influxdata.github.io/influxdb-client-php/
MIT License
150 stars 47 forks source link

\n in a field value breaks the FluxCsvParser #100

Closed gmoigneu closed 2 years ago

gmoigneu commented 2 years ago

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:

bednar commented 2 years ago

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

gmoigneu commented 2 years ago

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: "")
        })
    )