fix(writer-pipeline): handle ns0: XML namespace prefix in WebDAV PROPFIND parser (BIT-22306) #13
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',
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user