From d23fae5b6f96b876792326b8934ead0512e5d48a Mon Sep 17 00:00:00 2001 From: Jack Kavanagh Date: Thu, 7 Oct 2021 16:28:34 +0200 Subject: [PATCH] add missing text xpath type handler (#4083) --- packages/insomnia-xpath/src/query.test.ts | 7 +++++++ packages/insomnia-xpath/src/query.ts | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/packages/insomnia-xpath/src/query.test.ts b/packages/insomnia-xpath/src/query.test.ts index 4c54046f4..98894daf9 100644 --- a/packages/insomnia-xpath/src/query.test.ts +++ b/packages/insomnia-xpath/src/query.test.ts @@ -26,6 +26,13 @@ describe('query()', () => { ]); }); + it('handles text() query', () => { + expect(query('HarryPotter', 'local-name(/book)')) + .toEqual([{ 'inner': 'book', 'outer': 'book' }]); + expect(query('HarryPotter', '//title/text()')) + .toEqual([{ 'inner': 'Harry', 'outer': 'Harry' }, { 'inner': 'Potter', 'outer': 'Potter' }]); + }); + it('handles invalid query', () => { expect(() => { query('there', '//[]'); diff --git a/packages/insomnia-xpath/src/query.ts b/packages/insomnia-xpath/src/query.ts index b113d3e0c..2a515523b 100644 --- a/packages/insomnia-xpath/src/query.ts +++ b/packages/insomnia-xpath/src/query.ts @@ -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; }