Correct the behavior when field xpath is defined with a string function #1008
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sample xml
Normally user only specify xpath in the View definition, i.e:
bgp-peer: //bgp-peer/peer-id
Or use a string function as a condition for the xpath
//bgp-peer[starts-with(peer-state,'Essst')]
In these case lxml.etree return a list of lxml.etree._Element object, which work fine with the current view code.
However if we need to perform string manipulation, for example to extract IP from peer-address
substring-before(//bgp-peer/peer-address, "+")
, it will return a lxml.etree._ElementUnicodeResult object.This will be converted wrongly by the next interation (i.e address "1.1.1.1" will be iterated into a list)
We should return the original UnicodeResult.
The fix for this case is simple but I have not look further into other type of return from xml.xpath call, it'll be greate if anyone call look at that and cover all of other possible return.