Skip to content

Commit 323fbfe

Browse files
committed
fix validation test
1 parent d9f54e2 commit 323fbfe

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/validation/touchChatValidator.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ export class TouchChatValidator extends BaseValidator {
7676
}
7777
});
7878

79-
const zipped = await this.tryValidateZipSqlite(content);
79+
const looksLikeXml = this.isXmlBuffer(content);
80+
const zipped = looksLikeXml ? false : await this.tryValidateZipSqlite(content);
8081
if (!zipped) {
8182
let xmlObj: any = null;
8283
await this.add_check('xml_parse', 'valid XML', async () => {
@@ -275,6 +276,24 @@ export class TouchChatValidator extends BaseValidator {
275276
return true;
276277
}
277278

279+
private isXmlBuffer(content: Buffer | Uint8Array): boolean {
280+
const bytes = content instanceof Uint8Array ? content : new Uint8Array(content);
281+
const max = Math.min(bytes.length, 256);
282+
let start = 0;
283+
while (start < max) {
284+
const ch = bytes[start];
285+
if (ch === 0x20 || ch === 0x0a || ch === 0x0d || ch === 0x09) {
286+
start += 1;
287+
continue;
288+
}
289+
break;
290+
}
291+
if (start >= max) {
292+
return false;
293+
}
294+
return bytes[start] === 0x3c; // '<'
295+
}
296+
278297
private async tryValidateZipSqlite(content: Buffer | Uint8Array): Promise<boolean> {
279298
let usedZip = false;
280299
await this.add_check('zip', 'TouchChat ZIP package', async () => {

0 commit comments

Comments
 (0)