File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
lib/internal/Magento/Framework/Api Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,9 @@ public function __construct(array $data = [])
30
30
if (null !== $ this ->getDirection ()) {
31
31
$ this ->validateDirection ($ this ->getDirection ());
32
32
}
33
+ if ($ this ->getField () !== null ) {
34
+ $ this ->validateField ($ this ->getField ());
35
+ }
33
36
}
34
37
35
38
/**
@@ -50,6 +53,8 @@ public function getField()
50
53
*/
51
54
public function setField ($ field )
52
55
{
56
+ $ this ->validateField ($ field );
57
+
53
58
return $ this ->setData (SortOrder::FIELD , $ field );
54
59
}
55
60
@@ -127,4 +132,23 @@ private function normalizeDirectionInput($direction)
127
132
{
128
133
return strtoupper ($ direction );
129
134
}
135
+
136
+ /**
137
+ * Check if given value can be used as sorting field.
138
+ *
139
+ * @param string $field
140
+ * @return void
141
+ * @throws InputException
142
+ */
143
+ private function validateField (string $ field ): void
144
+ {
145
+ if (preg_match ('/[^a-z0-9\_]/i ' , $ field )) {
146
+ throw new InputException (
147
+ new Phrase (
148
+ 'Sort order field %1 contains restricted symbols ' ,
149
+ [$ field ]
150
+ )
151
+ );
152
+ }
153
+ }
130
154
}
Original file line number Diff line number Diff line change @@ -86,4 +86,14 @@ public function testItValidatesADirectionAssignedDuringInstantiation()
86
86
SortOrder::DIRECTION => 'not-asc-or-desc '
87
87
]);
88
88
}
89
+
90
+ /**
91
+ * @expectedException \Magento\Framework\Exception\InputException
92
+ */
93
+ public function testValidateField ()
94
+ {
95
+ $ this ->sortOrder = new SortOrder ([
96
+ SortOrder::FIELD => 'invalid field (value); '
97
+ ]);
98
+ }
89
99
}
You can’t perform that action at this time.
0 commit comments