From 63d613fccfecde3078ef7302a681abba412cc270 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Fri, 5 Feb 2021 23:02:15 +0200 Subject: [PATCH] fix(code.angularjs.org): correctly re-construct paths on Windows in `sendStoredFile()` Previously, the `sendStoredFile()` Firebase function used `.split('/')` to split the request path into segments and later used `path.join()` to join them back together. This worked fine on *nix based systems, which use `/` as the path separator. On Windows, however, where `\` is the path separator, the re-constructed paths could not be retrieved from the Google Cloud Storage bucket. This prevented the Firebase emulators from working correctly when testing the function locally on Windows. This commit fixes the issue by using `.join('/')` to join the path segments back together. Closes #17114 --- scripts/code.angularjs.org-firebase/functions/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/code.angularjs.org-firebase/functions/index.js b/scripts/code.angularjs.org-firebase/functions/index.js index 733c69479..a57280631 100644 --- a/scripts/code.angularjs.org-firebase/functions/index.js +++ b/scripts/code.angularjs.org-firebase/functions/index.js @@ -2,7 +2,6 @@ const functions = require('firebase-functions'); const {Storage} = require('@google-cloud/storage'); -const path = require('path'); const storage = new Storage(); const gcsBucketId = `${process.env.GCLOUD_PROJECT}.appspot.com`; @@ -41,13 +40,13 @@ function sendStoredFile(request, response) { return getDirectoryListing('/').catch(sendErrorResponse); } - downloadSource = path.join.apply(null, filePathSegments); + downloadSource = filePathSegments.join('/'); downloadAndSend(downloadSource).catch(error => { if (isDocsPath && error.code === 404) { fileName = 'index.html'; filePathSegments = [version, 'docs', fileName]; - downloadSource = path.join.apply(null, filePathSegments); + downloadSource = filePathSegments.join('/'); return downloadAndSend(downloadSource); }