Skip to content

Commit b82df2b

Browse files
committed
Split into multiple
1 parent bf0e563 commit b82df2b

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-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: 22 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,16 @@ public static function allowedXPathFilter(
132132
throw new Exception("Error in preg_replace.");
133133
}
134134

135+
self::validAllowedXpathFunctions($strippedValue, $allowed_fuctions);
136+
self::validAllowedXpathAxes($strippedValue, $allowed_axes);
137+
}
138+
139+
140+
public static function validAllowedXPathFunctions(
141+
string $value,
142+
array $allowed_functions = C::DEFAULT_ALLOWED_FUNCTIONS,
143+
string $message = '',
144+
): void {
135145
/**
136146
* Check if the $xpath_expression uses an XPath function that is not in the list of allowed functions
137147
*
@@ -140,7 +150,7 @@ public static function allowedXPathFilter(
140150
* All functions must match a string on a list of allowed function names
141151
*/
142152
$matches = [];
143-
$res = preg_match_all(self::$regex_xpfilter_functions, $strippedValue, $matches);
153+
$res = preg_match_all(self::$regex_xpfilter_functions, $value, $matches);
144154
if ($res === false) {
145155
throw new Exception("Error in preg_match_all.");
146156
}
@@ -154,7 +164,16 @@ public static function allowedXPathFilter(
154164
));
155165
}
156166
}
167+
}
157168

169+
170+
/**
171+
*/
172+
public static function validAllowedXPathAxes(
173+
string $value,
174+
array $allowed_axes = C::DEFAULT_ALLOWED_AXES,
175+
string $message = '',
176+
): void {
158177
/**
159178
* Check if the $xpath_expression uses an XPath axis that is not in the list of allowed axes
160179
*
@@ -163,7 +182,7 @@ public static function allowedXPathFilter(
163182
* All axes must match a string on a list of allowed axis names
164183
*/
165184
$matches = [];
166-
$res = preg_match_all(self::$regex_xpfilter_axes, $strippedValue, $matches);
185+
$res = preg_match_all(self::$regex_xpfilter_axes, $value, $matches);
167186
if ($res === false) {
168187
throw new Exception("Error in preg_match_all.");
169188
}

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)