From 34759cc0e0e63c952d7f8b7580f48144a063c684 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 19 Mar 2019 21:37:05 -0700 Subject: [PATCH] formatting' --- src/Illuminate/Validation/Rules/Unique.php | 6 +++--- tests/Validation/ValidationUniqueRuleTest.php | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Validation/Rules/Unique.php b/src/Illuminate/Validation/Rules/Unique.php index 0c210d31bf7f..64e910240382 100644 --- a/src/Illuminate/Validation/Rules/Unique.php +++ b/src/Illuminate/Validation/Rules/Unique.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() ), ','); diff --git a/tests/Validation/ValidationUniqueRuleTest.php b/tests/Validation/ValidationUniqueRuleTest.php index d6b64b727d4f..ebf15d2d048f 100644 --- a/tests/Validation/ValidationUniqueRuleTest.php +++ b/tests/Validation/ValidationUniqueRuleTest.php @@ -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');