diff --git a/src/services/textService.js b/src/services/textService.js index 2ba739d..a417f0d 100644 --- a/src/services/textService.js +++ b/src/services/textService.js @@ -153,8 +153,13 @@ async function optimizeText(buffer, mimeType, method) { output = result.data; } else if (mimeType === 'application/xml' || mimeType === 'text/xml') { // --- XML --- - // Strip XML comments - output = input.replace(//g, ''); + // Strip XML comments (repeat until stable to avoid incomplete multi-character sanitization) + output = input; + let previousOutput; + do { + previousOutput = output; + output = output.replace(//g, ''); + } while (output !== previousOutput); // Collapse whitespace between tags output = output.replace(/>\s+<'); if (isExtreme) {