AliceGenerator icon indicating copy to clipboard operation
AliceGenerator copied to clipboard

[ are not escaped in string property value

Open zhil opened this issue 8 years ago • 6 comments

[ are not escaped in string property value. Sample code

<?php
use Trappar\AliceGenerator\FixtureGeneratorBuilder;

class MyObject
{
    public $foo;
}

$obj = new MyObject();
$obj->foo = 'bar [value]';

$yaml = FixtureGeneratorBuilder::create()->build()->generateYaml($obj);
echo $yaml;

it output

AppBundle\Command\MyObject:
    MyObject-1:
        foo: 'bar [value]'

correct output

AppBundle\Command\MyObject:
    MyObject-1:
        foo: 'bar \[value\]'

zhil avatar May 15 '17 07:05 zhil

This may be an issue for the Symfony Yaml component... I'm not sure. I'll look into it later, or you can if you'd like.

trappar avatar May 15 '17 08:05 trappar

Actually, it looks like this is by design. Brackets only need to be inside quotes, they don't need to be escaped. Are you seeing an issue as a result of this?

trappar avatar May 15 '17 08:05 trappar

yes, such fixtures generate "Notice: Array to string conversion" (ContextErrorException)

Added screenshot of debugger, not sure how to explain better

sample fixture

ENTITY:
    Commentary-1:
        commentary: 'Welcome to [venue] where we are eagerly awaiting the arrival of the two teams'

image

zhil avatar May 15 '17 08:05 zhil

@trappar any ideas regarding how can it be fixed?

zhil avatar May 29 '17 10:05 zhil

@trappar sorry for annoying, do you have any ideas regarding how can it be fixed? Right now I use dirty patches like

public static function patchIssue12($content)
        {
            return preg_replace_callback('/^\s*commentary\:\s*\'(.+)\'$/mui',
                function($matches) {
                    return str_replace(['[',']','%'],['\[','\]','\%'],$matches[0]);
                },
                $content
            );
        }

I use patchIssue12() function before generating yaml files.

Do you have any ideas about clean way of fixing this issue?

zhil avatar Jul 08 '17 13:07 zhil

@trappar any ideas regarding how can we fix it in clean way?

zhil avatar Jul 27 '17 13:07 zhil