Passing xpath to XmlStructure::matchElement() always throws Exception
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Đọc src/Util/XmlStructure.php và đường đi của grabTextContentFrom() trong module SOAP, sau đó tạo một unit test tái hiện XPath như /example. Hoàn thành khi XPath không còn gây ra CSS selector exception và phần tử khớp được trả về.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
The signature allows param $cssOrXpath: https://github.com/Codeception/lib-xml/blob/main/src/Util/XmlStructure.php#L37
But when an xpath is passed, it will throw an exception.
This is broken since Codeception 5.0:
- v4 used to catch parser exceptions, and then continues to try an xpath: https://github.com/Codeception/Codeception/blob/4.2.2/src/Codeception/Util/XmlStructure.php#L39-L46
- v5 does not: https://github.com/Codeception/lib-xml/blob/main/src/Util/XmlStructure.php#L40
Reproduce
- Create a unit test and pass an xpath, for example through Codeceptions SOAP module
grabTextContentFrom()(https://codeception.com/docs/modules/SOAP#grabTextContentFrom):
$xpath = '/example';
$I->grabTextContentFrom($xpath))
- Run the test. Output:
1) ExampleCest: Call undefined operation
Test ExampleCest.php:example
[Symfony\Component\CssSelector\Exception\SyntaxErrorException] Expected selector, but <delimiter "/" at 0> found.
Scenario Steps:
4. $I->grabTextContentFrom("/example") at (..)
#1 (..)\vendor\symfony\css-selector\Exception\SyntaxErrorException.php:28
#2 (..)\vendor\symfony\css-selector\Parser\Parser.php:284
#3 (..)\vendor\symfony\css-selector\Parser\Parser.php:115
#4 (..)\vendor\symfony\css-selector\Parser\Parser.php:100
#5 (..)\vendor\symfony\css-selector\Parser\Parser.php:42
#6 (..)\vendor\symfony\css-selector\XPath\Translator.php:222
#7 (..)\vendor\symfony\css-selector\XPath\Translator.php:92
#8 (..)\vendor\symfony\css-selector\CssSelectorConverter.php:65
#9 Codeception\Module\SOAP->grabTextContentFrom
Possible fix
Re-implement the try-catch:
public function matchElement(string $cssOrXPath): ?DOMNode
{
$domXpath = new DOMXpath($this->xml);
try {
$selector = (new CssSelectorConverter())->toXPath($cssOrXPath);
$els = $domXpath->query($selector);
if ($els !== false && count($els) > 0) {
return $els->item(0);
}
} catch (\Symfony\Component\CssSelector\Exception\ParseException $e) {
}
$els = $domXpath->query($cssOrXPath);
if ($els !== false && count($els) > 0) {
return $els->item(0);
}
throw new ElementNotFound($cssOrXPath);
}
- Ngôn ngữ chính
- PHP
- Star
- 17
- Fork
- 1
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Codeception/lib-xml
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Codeception/lib-xml#7 ·
Tất cả issue của Codeception/lib-xml
Issue tương tự
-
priority: p3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
nextcloud/fulltextsearch#1011 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
phpstan/phpstan-doctrine#794 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Automattic/static-site-importer#1767 ·