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 4de8643360
commit 43ec591414
+16 -6
View File
@@ -89,12 +89,22 @@ function sortRemoteItems(items: RemoteBackupItem[]): RemoteBackupItem[] {
}
function decodeXmlText(value: string): string {
return value
.replace(/&/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/g, '"')
.replace(/&#39;/g, "'");
return value.replace(/&(amp|lt|gt|quot|#39);/g, (_match, entity) => {
switch (entity) {
case 'amp':
return '&';
case 'lt':
return '<';
case 'gt':
return '>';
case 'quot':
return '"';
case '#39':
return "'";
default:
return _match;
}
});
}
function parseHttpDate(value: string): string | null {