Skip to content

Commit

Permalink
formatting'
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Mar 20, 2019
1 parent 7dc58cd commit 34759cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Illuminate/Validation/Rules/Unique.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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()
), ',');
Expand Down
7 changes: 7 additions & 0 deletions tests/Validation/ValidationUniqueRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

1 comment on commit 34759cc

@event15
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is definitely formatting commit.

Please sign in to comment.