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;