adm-zip icon indicating copy to clipboard operation
adm-zip copied to clipboard

Error when running updateFile() on an entry marked as read-only

Open carpiediem opened this issue 7 years ago • 1 comments

Expected behavior Either the function returns an error, pointing out that the file is set as read-only or the file is updated as requested, ignoring the setting.

Actual behavior File was updated with a portion of the string I sent to it (not the full contents).

const zip = new AdmZip(existingZipFilename);
const existingText= zip.readAsText(pathToFile);
const modifiedText = existingText.replace('</html>', '<script type="text/javascript" src="../../../plugin.js"></script></html>');
zip.updateFile(pathToFile, Buffer.alloc(modifiedText .length, modifiedText ), 'Injecting script tag');
zip.writeZip(newZipFilename);

This is a bit of pseudo-code that works for archives that have all files with read-only unset. However, when read-only is set for the file at pathToFile, the result is that the file in the new archive ends like this:

<script type="text/javascript" src="../../../plu

instead of like this:

<script type="text/javascript" src="../../../plugin.js"></script></html>

All the preceding contents of the file are there in both cases. Any ideas why that would happen?

carpiediem avatar Sep 10 '18 12:09 carpiediem

Actually, after some more testing, it doesn't seem to be related to the read-only status. I'm still getting the error with this one particular archive, but I can't figure out what's different about this case...

pathToFile in this case starts with \U. Is there any chance that something is thrown off by a Unicode escape?

carpiediem avatar Sep 10 '18 12:09 carpiediem