feat: optimize XML decoding by using a switch statement for entity replacements

This commit is contained in:
shuaiplus
2026-03-16 00:58:13 +08:00
parent 2ebd0b60f7
commit 623ad1acda
+16 -6
View File
@@ -89,12 +89,22 @@ function sortRemoteItems(items: RemoteBackupItem[]): RemoteBackupItem[] {
} }
function decodeXmlText(value: string): string { function decodeXmlText(value: string): string {
return value return value.replace(/&(amp|lt|gt|quot|#39);/g, (_match, entity) => {
.replace(/&/g, '&') switch (entity) {
.replace(/&lt;/g, '<') case 'amp':
.replace(/&gt;/g, '>') return '&';
.replace(/&quot;/g, '"') case 'lt':
.replace(/&#39;/g, "'"); return '<';
case 'gt':
return '>';
case 'quot':
return '"';
case '#39':
return "'";
default:
return _match;
}
});
} }
function parseHttpDate(value: string): string | null { function parseHttpDate(value: string): string | null {