phonegap / connect-phonegap

Stream a PhoneGap app to any device.
Apache License 2.0
61 stars 63 forks source link

Multiple bugs from using `str.split(sub)[1]` to remove substring from strings #205

Closed NgoKimPhu closed 6 years ago

NgoKimPhu commented 6 years ago

Original Issue

zip file from GET /__api__/appzip is corrupted when process.cwd() is a substring of some file's relative filepath

PhoneGap CLI, node & npm versions

phonegap 6.5.2 node 6.11.0 npm 3.10.10

Expected Behaviour

zip file received from GET /__api__/appzip should be in correct format

Actual Behaviour

Files written with wrong name within the zip leading to corrupted appzip file

Steps to Reproduce

Put your project in /app (like Heroku does) process.cwd() === '/app' Make a file beginning with app, e.g. app.js or app.css When zipping file /app/www/js/app.js, the code at https://github.com/phonegap/connect-phonegap/blob/f7c661e/lib/middleware/zip.js#L72 will generate a relative link of /www/js instead of /www/js/app.js, corrupting the zip file

Code that causes the problem

var output = pathWithSymlinks(filename).split(process.cwd())[1];

Error messages

$ unzip appzip
...
checkdir error:  www/js exists but is not directory
                 unable to process www/js/otherJsFilesInTheSameFolder.js.

Note

This code exists in multiple places within the code base.

timkim commented 6 years ago

Hi @NgoKimPhu

Thanks for these prs! I'm working through some other stuff at the moment but I'll try to merge them next week.

NgoKimPhu commented 6 years ago

Thanks @timkim. At your own pace

timkim commented 6 years ago

Thanks for the prs!