add missing text xpath type handler (#4083)

This commit is contained in:
Jack Kavanagh 2021-10-07 16:28:34 +02:00 committed by GitHub
parent e793e6f166
commit d23fae5b6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -26,6 +26,13 @@ describe('query()', () => {
]);
});
it('handles text() query', () => {
expect(query('<book><title>Harry</title><title>Potter</title></book>', 'local-name(/book)'))
.toEqual([{ 'inner': 'book', 'outer': 'book' }]);
expect(query('<book><title>Harry</title><title>Potter</title></book>', '//title/text()'))
.toEqual([{ 'inner': 'Harry', 'outer': 'Harry' }, { 'inner': 'Potter', 'outer': 'Potter' }]);
});
it('handles invalid query', () => {
expect(() => {
query('<hi>there</hi>', '//[]');

View File

@ -43,6 +43,13 @@ export const query = (xml: string, query?: string) => {
});
break;
case 'Text':
output.push({
outer: (selectedValue as Text).toString().trim(),
inner: (selectedValue as Text).toString().trim(),
});
break;
default:
break;
}