-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Asserts with unmatched XPath nodes #503
Comments
Maybe another possible fix, that might be more general: I guess the fundamental issue is that trying to convert an expected string value into the current target value is inherently fragile, even when matching JSON or other sources. If the target value is not a string as expected that process is likely to crash. So a better fix could be to wrap that JSON parse in a try..catch and cleanly fail the assert when the target and expected value types are incompatible. (might still be nice to convert a non-matching xpath selector into |
@jods4 Yeah, what can I say. I agree with you on all points. You can tell that I don't use the XPath myself. For objects, it currently works rather mediocre. My asserts are either very simple or I use the javascript notation right away. |
Thank you! |
update is released with v6.6.1 |
When no node matches an XPath assert, the (string) expected value is parsed as JSON and this crashes httpyac instead of cleaning failing the assert.
I looked at the code and I think I know what happens.
provideAssertValueXPath
usesxpath
lib to select the matching nodes. If no node in response matches, this would be an empty array.provideAssertValueXPath
maps the array to strings, but the final provided value remains an empty array.https://github.com/AnWeber/httpyac/blob/main/src/plugins/xml/provideAssertValueXPath.ts#L40-L44
I suggest this is where the fix might be: add a case for empty array, and return undefined instead?
parseAssertLine
attempts an auto-conversion of expected value to actual value type.https://github.com/AnWeber/httpyac/blob/main/src/plugins/assert/assertHttpRegionParser.ts#L57
When XPath matched a node, the target value is a string and there's no conversion: it works great.
But when there's no match, target value is an empty array, and the auto-conversion attempts to parse the expected value as JSON.
https://github.com/AnWeber/httpyac/blob/main/src/plugins/assert/assertHttpRegionParser.ts#L98-L100
The text was updated successfully, but these errors were encountered: