From 738c1a56d08749997eb0a290bc720bfa80fe98e2 Mon Sep 17 00:00:00 2001 From: Artur Moreira Date: Thu, 14 May 2026 16:33:49 +0000 Subject: [PATCH] fix(writer-pipeline): handle ns0: XML namespace prefix in WebDAV PROPFIND parser (BIT-22306) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Python's xml.etree.ElementTree auto-assigns numeric prefixes like ns0: for the first namespace it encounters. The PROPFIND regex [a-z]+: did not match ns0: because of the digit, causing parsePropfindImageHrefs to return empty on any WebDAV server backed by Python (WsgiDAV, some NextCloud configs). Change [a-z]+: → [a-z][a-z0-9]*: in all three namespace-tagged element patterns (response, href, getlastmodified). Test added with a real WsgiDAV multistatus fixture. Paperclip-Issue: BIT-22306 --- writer-pipeline/src/webdav-archive.test.ts | 9 +++++++++ writer-pipeline/src/webdav-archive.ts | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/writer-pipeline/src/webdav-archive.test.ts b/writer-pipeline/src/webdav-archive.test.ts index 3b7dcfb..3a4d9d3 100644 --- a/writer-pipeline/src/webdav-archive.test.ts +++ b/writer-pipeline/src/webdav-archive.test.ts @@ -24,6 +24,15 @@ test('parsePropfindImageHrefs skips collection root and lists image files', () = assert.equal(rows[0].lastMod, 'Wed, 01 Jan 2025 12:00:00 GMT'); }); +test('parsePropfindImageHrefs handles ns0: namespace prefix (WsgiDAV / Python ElementTree)', () => { + const xml = ` +/Thu, 14 May 2026 16:11:04 GMTHTTP/1.1 200 OK/Foto_FPA___duplo-embate-croacia-m20-euro.jpgThu, 14 May 2026 16:11:26 GMTHTTP/1.1 200 OK`; + const rows = parsePropfindImageHrefs(xml, 'http://127.0.0.1:8088/'); + assert.equal(rows.length, 1); + assert.match(rows[0].href, /Foto_FPA___duplo-embate-croacia-m20-euro\.jpg$/); + assert.equal(rows[0].lastMod, 'Thu, 14 May 2026 16:11:26 GMT'); +}); + test('pickBestArchiveImage prefers hrefs whose path matches title tokens', () => { const item: AggregatedItem = { id: '1', diff --git a/writer-pipeline/src/webdav-archive.ts b/writer-pipeline/src/webdav-archive.ts index 08743f0..15133d9 100644 --- a/writer-pipeline/src/webdav-archive.ts +++ b/writer-pipeline/src/webdav-archive.ts @@ -29,14 +29,14 @@ function decodeXmlText(s: string): string { export function parsePropfindImageHrefs(xml: string, collectionUrl: string): { href: string; lastMod?: string }[] { const base = new URL(collectionUrl.endsWith('/') ? collectionUrl : `${collectionUrl}/`); const out: { href: string; lastMod?: string }[] = []; - const reResponse = /<(?:[a-z]+:)?response[^>]*>([\s\S]*?)<\/(?:[a-z]+:)?response>/gi; + const reResponse = /<(?:[a-z][a-z0-9]*:)?response[^>]*>([\s\S]*?)<\/(?:[a-z][a-z0-9]*:)?response>/gi; let m: RegExpExecArray | null; while ((m = reResponse.exec(xml))) { const block = m[1]; - const hrefM = /<(?:[a-z]+:)?href>([^<]+)<\/(?:[a-z]+:)?href>/i.exec(block); + const hrefM = /<(?:[a-z][a-z0-9]*:)?href>([^<]+)<\/(?:[a-z][a-z0-9]*:)?href>/i.exec(block); if (!hrefM) continue; const hrefRaw = decodeXmlText(hrefM[1].trim()); - const lmM = /<(?:[a-z]+:)?getlastmodified>([^<]+)<\/(?:[a-z]+:)?getlastmodified>/i.exec(block); + const lmM = /<(?:[a-z][a-z0-9]*:)?getlastmodified>([^<]+)<\/(?:[a-z][a-z0-9]*:)?getlastmodified>/i.exec(block); const lastMod = lmM ? decodeXmlText(lmM[1].trim()) : undefined; if (!IMAGE_EXT_RE.test(hrefRaw)) continue; let abs: string;