Skip to content
Permalink
Browse files

formatting'

  • Loading branch information...
taylorotwell committed Mar 20, 2019
1 parent 7dc58cd commit 34759cc0e0e63c952d7f8b7580f48144a063c684
Showing with 10 additions and 3 deletions.
  1. +3 −3 src/Illuminate/Validation/Rules/Unique.php
  2. +7 −0 tests/Validation/ValidationUniqueRuleTest.php
@@ -35,7 +35,7 @@ public function ignore($id, $idColumn = null)
return $this->ignoreModel($id, $idColumn);
}
$this->ignore = addslashes($id);
$this->ignore = $id;
$this->idColumn = $idColumn ?? 'id';
return $this;
@@ -50,7 +50,7 @@ public function ignore($id, $idColumn = null)
*/
public function ignoreModel($model, $idColumn = null)
{
$this->idColumn = addslashes($idColumn ?? $model->getKeyName());
$this->idColumn = $idColumn ?? $model->getKeyName();
$this->ignore = $model->{$this->idColumn};
return $this;
@@ -66,7 +66,7 @@ public function __toString()
return rtrim(sprintf('unique:%s,%s,%s,%s,%s',
$this->table,
$this->column,
$this->ignore ? '"'.$this->ignore.'"' : 'NULL',
$this->ignore ? '"'.addslashes($this->ignore).'"' : 'NULL',
$this->idColumn,
$this->formatWheres()
), ',');
@@ -19,6 +19,13 @@ public function testItCorrectlyFormatsAStringVersionOfTheRule()
$rule->where('foo', 'bar');
$this->assertEquals('unique:table,column,"Taylor, Otwell",id_column,foo,bar', (string) $rule);
$rule = new Unique('table', 'column');
$rule->ignore('Taylor, Otwell"\'..-"', 'id_column');
$rule->where('foo', 'bar');
$this->assertEquals('unique:table,column,"Taylor, Otwell\"\\\'..-\"",id_column,foo,bar', (string) $rule);
$this->assertEquals('Taylor, Otwell"\'..-"', stripslashes(str_getcsv('table,column,"Taylor, Otwell\"\\\'..-\"",id_column,foo,bar')[2]));
$this->assertEquals('id_column', stripslashes(str_getcsv('table,column,"Taylor, Otwell\"\\\'..-\"",id_column,foo,bar')[3]));
$rule = new Unique('table', 'column');
$rule->ignore(null, 'id_column');
$rule->where('foo', 'bar');

1 comment on commit 34759cc

@event15

This comment has been minimized.

Copy link

commented on 34759cc Mar 20, 2019

Yes, there is definitely formatting commit.

Please sign in to comment.
You can’t perform that action at this time.