Exporting a long text field, it is possible to have indentation in the value.

Lorem Ipsum dolor sit amet:
                                        Lorem ipsum

Unfortunately CsvEncoder->arrayDepth() is using print_r and indentation to determine the depth of an value array. Above string returns a depth of 6 and therefore output for the field value is removed in CsvEncoder->flattenCell().

My approach is to determine reference by setting a test key, but if there are other ideas...

Comments

volkerk created an issue. See original summary.

volkerk’s picture

Status: Active » Needs review
StatusFileSize
new1.47 KB
grasmash’s picture

A few alternatives here: https://stackoverflow.com/questions/262891/is-there-a-way-to-find-out-ho...

I like...

function getArrayDepth($array) {
    $depth = 0;
    $iteIte = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));

    foreach ($iteIte as $ite) {
        $d = $iteIte->getDepth();
        $depth = $d > $depth ? $d : $depth;
    }

    return $depth;
}
grasmash’s picture

Status: Needs review » Needs work
miritas’s picture

Hello.

@Vokerk

Seems there is an inaccuracy in the code. I believe that such changes are required:

+ $copy[$key]['__test'] == true;

+ $copy[$key]['__test'] = true;

@grasmash

Your example is not resistant to infinity recursion that can appear because of references.

Regards.

michelle’s picture

This patch doesn't fix the core issue, so I'm going to leave the status as needs work. What it does is add in a check to ensure the process doesn't crash when it gets the array depth wrong. I think this is a useful addition even once the real patch for this issue is in as it's a good failsafe.

steinmb’s picture

Priority: Normal » Major
Related issues: +#3120645: TypeError in CsvEncoder.php

Bumping to major as i totally breaks and prevent us from doing any useful with it when we hit this.

michelle’s picture

Removing my patch from the list. I missed doing it when I uploaded it. Since my patch is just a helpful failsafe while we wait on a real fix, I don't want it showing up in the top post and confusing people.

singularo’s picture

Alternate approach - trim the leading spaces off - Feels hacky though.

markdorison’s picture

Status: Needs work » Closed (outdated)

Is this issue still relevant? If so, please reopen with a merge request against the 4.x branch.