Passing xpath to XmlStructure::matchElement() always throws Exception
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 45/100
Rechercherichtung
Lies src/Util/XmlStructure.php und den Pfad von grabTextContentFrom() im SOAP-Modul und erstelle anschließend einen Unit-Test, der einen XPath wie /example reproduziert. Erledigt ist die Aufgabe, wenn der XPath keine CSS-Selector-Exception mehr auslöst und das passende Element zurückgegeben wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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);
}
- Vorherrschende Sprache
- PHP
- Sterne
- 17
- Forks
- 1
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus Codeception/lib-xml
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
Codeception/lib-xml#7 ·
Alle Issues in Codeception/lib-xml
Ähnliche Issues
-
Daemon delete dialog: "Remove all ExApps" checkbox and `removeExApps` parameter have no effectOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
Maintainer antworten meist innerhalb von 1 Tag
-
[Sync EN] Fix session read handler docs: false reports a failure, not a missing session (#5902)Offensync-en
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
[Sync EN] Fix session read handler docs: false reports a failure, not a missing session (#5902)Offensync-en
Schwierigkeit 2/5 1-2 Tage Anfängerfreundlichkeit 84/100
Maintainer antworten meist innerhalb von 2 Tagen
-
feature-request needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
aws/aws-sdk-php#3365 ·
Maintainer antworten meist innerhalb von 1 Tag