Yii2: Migration tool. Create migrate with comma in defaultValue

Created on 29 Apr 2016  路  18Comments  路  Source: yiisoft/yii2

The issue like that: https://github.com/yiisoft/yii2/issues/10969
If "defaultValue" contains comma, incorrect code will be generated.

yii migrate/create add_field_to_table 
--fields="title:string(10):notNull:unique:defaultValue('te,st'),body:text:notNull"
medium ready for adoption bug

All 18 comments

Confirmed. Would you like to fix the regexp and submit a PR?

@s-o-f @SilverFire i can handle it ;)

@s-o-f @s1lver check my pr please https://github.com/yiisoft/yii2/pull/11463

@pana1990
Not worked with
defaultValue('te,s,t')
and
defaultValue( 'te,s,t' ) whitespaces between "(" and '
also
defaultValue(',')

Some tests: https://regex101.com/r/gZ5dH3/1

ups, its true, any suggestion?

Maybe something like this:
(?!\((\'|")*[^"\']+)\s*,\s*(?![^"\']*(\'|")*\))
Tests: https://regex101.com/r/gZ5dH3/2

UPD: not working(

@s-o-f try it this one, please :

(?!\((\'|")*[^"\']+)\s*,\s*((?![^"\'(\)]*(\'|")*\)))

it pass your examples :

https://regex101.com/r/gZ5dH3/4

are there other case where it can fail?

Last two lines fails
https://regex101.com/r/gZ5dH3/5

yes, let's me try again.

@pana1990
Your last variant fails at last line here: https://regex101.com/r/gZ5dH3/8
How about this: (?!\([^\s*\,])\s*,\s*(?!.*('|")\))
https://regex101.com/r/gZ5dH3/9

@s-o-f it fails in the following example :

< sdfsf,sdfsdf,asdsd(),sdfsdf('3',33,"22"), > without end line.

https://regex101.com/r/gZ5dH3/10

we should use https://regex101.com/ before making more commits. That way everyone can test the provided regex easily

@pana1990
Maybe this: (?!\([^\s*\,])\s*,\s*(?![^"']*('|")\))
https://regex101.com/r/gZ5dH3/11

In this sdfsdf('3',33, "22") you can't use ' and ", then migrate command will be invalid:

yii migrate/create add_field_to_table 
--fields="title:string(10):notNull:unique:defaultValue('3',33, "22"),body:text:notNull"

Huh, not so easy :laughing:

The last one seems to be correct.

In this sdfsdf('3',33, "22") you can't use ' and "

It's a kind of shooting yourself in the foot. Don't take care too much about this case :)

@s-o-f

this example fails :

title:string(10):notNull:unique:defaultValue("test"),body:text:notNull,price:money(11,2):notNull

@s-o-f @SilverFire

I thingk to find to solution :

\s*,\s*(?![^()]*\))

https://regex101.com/r/gZ5dH3/14

are there other case where it can fail?
```

i think it is okey, can you check it? @s-o-f @SilverFire

thanks in advanced

Was this page helpful?
0 / 5 - 0 ratings