Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 1d97cf9

Browse files
committed
chore(*): fix serving of URI-encoded files on code.angularjs.org
The files served for the various versions on https://code.angularjs.org/ are retrieved by a Firebase function from a Firebase Storage bucket (where they are deployed to from Travis CI). The files are stored exactly as they are named on disk. It turns out that some of the files have names with special characters that get URI-encoded when sent to the Firebase function. For example, `input[text].html` becomes `input%5Btext%5D.html`. As a result, the actual file cannot be retrieved from the Storage bucket (since the name does not match) and `index.html` is returned instead. Apparently, this never worked, but nobody noticed or reported it until recently. An example of a failing URL is: https://code.angularjs.org/1.7.9/docs/api/ng/input/input%5Btext%5D (NOTE: https://docs.angularjs.org/ works correctly, since the files are deployed to Firebase hosting directly and not to a Storage bucket.) This commit fixes the problem by decoding the request path before trying to retrieve the corresponding file from the Storage bucket. Closes #16943
1 parent 479699f commit 1d97cf9

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ performance/temp*.html
1212
angular.js.tmproj
1313
node_modules/
1414
angular.xcodeproj
15+
.firebase/
1516
.idea
1617
*.iml
1718
.agignore

scripts/code.angularjs.org-firebase/functions/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ const BROWSER_CACHE_DURATION = 60 * 10;
1010
const CDN_CACHE_DURATION = 60 * 60 * 12;
1111

1212
function sendStoredFile(request, response) {
13-
const requestPath = request.path || '/';
13+
// Request paths will be URI-encoded, so we need to decode them to match the file names in the
14+
// storage bucket. Failing to do so will result in a 404 error from the bucket and `index.html`
15+
// will be returned instead.
16+
// Example of path requiring decoding: `.../input%5Btext%5D.html` --> `.../input[text].html`
17+
const requestPath = decodeURI(request.path || '/');
1418
let filePathSegments = requestPath.split('/').filter((segment) => {
1519
// Remove empty leading or trailing path parts
1620
return segment !== '';

scripts/code.angularjs.org-firebase/functions/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "functions-firebase-code.angularjs.org",
33
"description": "Cloud Functions to serve files from gcs to code.angularjs.org",
4+
"engines": {
5+
"node": "8"
6+
},
47
"dependencies": {
58
"@google-cloud/storage": "^1.1.1",
69
"firebase-admin": "^5.11.0",

0 commit comments

Comments
 (0)