Skip to content

Commit 34759cc

Browse files
committed
formatting'
1 parent 7dc58cd commit 34759cc

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Illuminate/Validation/Rules/Unique.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function ignore($id, $idColumn = null)
3535
return $this->ignoreModel($id, $idColumn);
3636
}
3737

38-
$this->ignore = addslashes($id);
38+
$this->ignore = $id;
3939
$this->idColumn = $idColumn ?? 'id';
4040

4141
return $this;
@@ -50,7 +50,7 @@ public function ignore($id, $idColumn = null)
5050
*/
5151
public function ignoreModel($model, $idColumn = null)
5252
{
53-
$this->idColumn = addslashes($idColumn ?? $model->getKeyName());
53+
$this->idColumn = $idColumn ?? $model->getKeyName();
5454
$this->ignore = $model->{$this->idColumn};
5555

5656
return $this;
@@ -66,7 +66,7 @@ public function __toString()
6666
return rtrim(sprintf('unique:%s,%s,%s,%s,%s',
6767
$this->table,
6868
$this->column,
69-
$this->ignore ? '"'.$this->ignore.'"' : 'NULL',
69+
$this->ignore ? '"'.addslashes($this->ignore).'"' : 'NULL',
7070
$this->idColumn,
7171
$this->formatWheres()
7272
), ',');

tests/Validation/ValidationUniqueRuleTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ public function testItCorrectlyFormatsAStringVersionOfTheRule()
1919
$rule->where('foo', 'bar');
2020
$this->assertEquals('unique:table,column,"Taylor, Otwell",id_column,foo,bar', (string) $rule);
2121

22+
$rule = new Unique('table', 'column');
23+
$rule->ignore('Taylor, Otwell"\'..-"', 'id_column');
24+
$rule->where('foo', 'bar');
25+
$this->assertEquals('unique:table,column,"Taylor, Otwell\"\\\'..-\"",id_column,foo,bar', (string) $rule);
26+
$this->assertEquals('Taylor, Otwell"\'..-"', stripslashes(str_getcsv('table,column,"Taylor, Otwell\"\\\'..-\"",id_column,foo,bar')[2]));
27+
$this->assertEquals('id_column', stripslashes(str_getcsv('table,column,"Taylor, Otwell\"\\\'..-\"",id_column,foo,bar')[3]));
28+
2229
$rule = new Unique('table', 'column');
2330
$rule->ignore(null, 'id_column');
2431
$rule->where('foo', 'bar');

0 commit comments

Comments
 (0)