Passing xpath to XmlStructure::matchElement() always throws Exception
還沒有人認領這個 Issue。
評估
研究方向
閱讀 src/Util/XmlStructure.php 和 SOAP 模組的 grabTextContentFrom() 路徑,然後建立一個重現類似 /example 的 XPath 的單元測試。完成標準是 XPath 不再引發 CSS selector exception,並回傳符合的元素。
由索引模型根據 Issue 內容生成。
描述
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);
}
- 主要語言
- PHP
- 星號
- 17
- 分支
- 1
- PR 合併指標
- 30 天內沒有已合併 PR
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
Codeception/lib-xml 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 65/100
Codeception/lib-xml#7 ·
查看 Codeception/lib-xml 的全部 Issue
相似的 Issue
-
sync-en
難度 1/5 1-3 小時 新手友好度 88/100
-
sync-en
難度 1/5 1-3 小時 新手友好度 88/100
-
Перевод устарел
難度 1/5 1-3 小時 新手友好度 88/100
-
priority: p3
難度 2/5 1-3 小時 新手友好度 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
難度 2/5 1-3 小時 新手友好度 78/100
nextcloud/fulltextsearch#1011 ·