fix(writer-pipeline): handle ns0: XML namespace prefix in WebDAV PROPFIND parser (BIT-22306)
Tests / writer-pipeline tests (push) Successful in 14s
Tests / bridge tests (push) Successful in 14s
Tests / frontend lib tests (push) Successful in 15s
Tests / writer-pipeline tests (pull_request) Successful in 11s
Tests / bridge tests (pull_request) Successful in 12s
Tests / frontend lib tests (pull_request) Successful in 13s

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
This commit is contained in:
Artur Moreira committed 2026-05-14 16:33:49 +00:00
1 parent 9d03d489e0
commit 738c1a56d0
2 files changed
+12 -3

No files matched your search

@@ -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 = `<?xml version="1.0" encoding="utf-8" ?>
<ns0:multistatus xmlns:ns0="DAV:"><ns0:response><ns0:href>/</ns0:href><ns0:propstat><ns0:prop><ns0:getlastmodified>Thu, 14 May 2026 16:11:04 GMT</ns0:getlastmodified><ns0:resourcetype><ns0:collection /></ns0:resourcetype></ns0:prop><ns0:status>HTTP/1.1 200 OK</ns0:status></ns0:propstat></ns0:response><ns0:response><ns0:href>/Foto_FPA___duplo-embate-croacia-m20-euro.jpg</ns0:href><ns0:propstat><ns0:prop><ns0:getlastmodified>Thu, 14 May 2026 16:11:26 GMT</ns0:getlastmodified><ns0:resourcetype /></ns0:prop><ns0:status>HTTP/1.1 200 OK</ns0:status></ns0:propstat></ns0:response></ns0:multistatus>`;
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',
+3 -3
View File
@@ -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;