Skip to content

Commit f3c2f16

Browse files
committed
Split into multiple
1 parent bf0e563 commit f3c2f16

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

src/Assert/Assert.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,29 @@
99
/**
1010
* @package simplesamlphp/xml-common
1111
*
12+
* @method static void validAllowedXPathAxes(mixed $value, array $allowed_axes, string $message = '', string $exception = '')
13+
* @method static void validAllowedXPathFilter(mixed $value, array $allowed_axes, array $allowed_functions, string $message = '', string $exception = '')
14+
* @method static void validAllowedXPathFunctions(mixed $value, array $allowed_functions, string $message = '', string $exception = '')
1215
* @method static void validHexBinary(mixed $value, string $message = '', string $exception = '')
1316
* @method static void validNMToken(mixed $value, string $message = '', string $exception = '')
1417
* @method static void validNMTokens(mixed $value, string $message = '', string $exception = '')
1518
* @method static void validDuration(mixed $value, string $message = '', string $exception = '')
1619
* @method static void validDateTime(mixed $value, string $message = '', string $exception = '')
1720
* @method static void validNCName(mixed $value, string $message = '', string $exception = '')
1821
* @method static void validQName(mixed $value, string $message = '', string $exception = '')
22+
* @method static void nullOrValidAllowedXPathAxes(mixed $value, array $allowed_axes, string $message = '', string $exception = '')
23+
* @method static void nullOrValidAllowedXPathFilter(mixed $value, array $allowed_axes, array $allowed_functions, string $message = '', string $exception = '')
24+
* @method static void nullOrValidAllowedXPathFunctions(mixed $value, array $allowed_functions, string $message = '', string $exception = '')
1925
* @method static void nullOrValidHexBinary(mixed $value, string $message = '', string $exception = '')
2026
* @method static void nullOrValidNMToken(mixed $value, string $message = '', string $exception = '')
2127
* @method static void nullOrValidNMTokens(mixed $value, string $message = '', string $exception = '')
2228
* @method static void nullOrValidDuration(mixed $value, string $message = '', string $exception = '')
2329
* @method static void nullOrValidDateTime(mixed $value, string $message = '', string $exception = '')
2430
* @method static void nullOrValidNCName(mixed $value, string $message = '', string $exception = '')
2531
* @method static void nullOrValidQName(mixed $value, string $message = '', string $exception = '')
32+
* @method static void allValidAllowedXPathAxes(mixed $value, array $allowed_axes, string $message = '', string $exception = '')
33+
* @method static void allValidAllowedXPathFilter(mixed $value, array $allowed_axes, array $allowed_functions, string $message = '', string $exception = '')
34+
* @method static void allValidAllowedXPathFunctions(mixed $value, array $allowed_functions, string $message = '', string $exception = '')
2635
* @method static void allValidHexBinary(mixed $value, string $message = '', string $exception = '')
2736
* @method static void allValidNMToken(mixed $value, string $message = '', string $exception = '')
2837
* @method static void allValidNMTokens(mixed $value, string $message = '', string $exception = '')

src/Assert/XPathFilterTrait.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ trait XPathFilterTrait
107107
* @param array<string> $allowed_functions
108108
* @param string $message
109109
*/
110-
public static function allowedXPathFilter(
110+
public static function validAllowedXPathFilter(
111111
string $value,
112112
array $allowed_axes = C::DEFAULT_ALLOWED_AXES,
113113
array $allowed_functions = C::DEFAULT_ALLOWED_FUNCTIONS,
@@ -132,6 +132,21 @@ public static function allowedXPathFilter(
132132
throw new Exception("Error in preg_replace.");
133133
}
134134

135+
self::validAllowedXpathFunctions($strippedValue, $allowed_functions);
136+
self::validAllowedXpathAxes($strippedValue, $allowed_axes);
137+
}
138+
139+
140+
/**
141+
* @param string $value
142+
* @param array<string> $allowed_functions
143+
* @param string $message
144+
*/
145+
public static function validAllowedXPathFunctions(
146+
string $value,
147+
array $allowed_functions = C::DEFAULT_ALLOWED_FUNCTIONS,
148+
string $message = '',
149+
): void {
135150
/**
136151
* Check if the $xpath_expression uses an XPath function that is not in the list of allowed functions
137152
*
@@ -140,7 +155,7 @@ public static function allowedXPathFilter(
140155
* All functions must match a string on a list of allowed function names
141156
*/
142157
$matches = [];
143-
$res = preg_match_all(self::$regex_xpfilter_functions, $strippedValue, $matches);
158+
$res = preg_match_all(self::$regex_xpfilter_functions, $value, $matches);
144159
if ($res === false) {
145160
throw new Exception("Error in preg_match_all.");
146161
}
@@ -154,7 +169,19 @@ public static function allowedXPathFilter(
154169
));
155170
}
156171
}
172+
}
173+
157174

175+
/**
176+
* @param string $value
177+
* @param array<string> $allowed_axes
178+
* @param string $message
179+
*/
180+
public static function validAllowedXPathAxes(
181+
string $value,
182+
array $allowed_axes = C::DEFAULT_ALLOWED_AXES,
183+
string $message = '',
184+
): void {
158185
/**
159186
* Check if the $xpath_expression uses an XPath axis that is not in the list of allowed axes
160187
*
@@ -163,7 +190,7 @@ public static function allowedXPathFilter(
163190
* All axes must match a string on a list of allowed axis names
164191
*/
165192
$matches = [];
166-
$res = preg_match_all(self::$regex_xpfilter_axes, $strippedValue, $matches);
193+
$res = preg_match_all(self::$regex_xpfilter_axes, $value, $matches);
167194
if ($res === false) {
168195
throw new Exception("Error in preg_match_all.");
169196
}

tests/Assert/XPathFilterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testDefaultAllowedXPathFilter(
3535
array $functions = C::DEFAULT_ALLOWED_FUNCTIONS,
3636
): void {
3737
try {
38-
XMLAssert::allowedXPathFilter($filter, $axes, $functions);
38+
XMLAssert::validAllowedXPathFilter($filter, $axes, $functions);
3939
$this->assertTrue($shouldPass);
4040
} catch (AssertionFailedException $e) {
4141
$this->assertFalse($shouldPass);

0 commit comments

Comments
 (0)