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

Commit 61ad68a

Browse files
gkalpakthePunderWoman
authored andcommitted
fix(docs-infra): do not redirect disambiguated URLs (#41842) (#41854)
In #41788, logic was added to disambiguate case-insensitively equal docs paths/URLs. This process includes appending a `-\d+` suffix to some paths/URLs (for example, `/.../inject-1`). Unfortunately, some of the Firebase redirects configured in `firebase.json` would match these URLs and redirect them to non-existing paths. Example failures: [stable][1], [next][2] NOTE: This was not picked up in the regular CI tests run for PRs, because the local devserver and the preview server used to test PRs do not support Firebase-like redirects. This commit fixes this by ensuring these disambiguated paths/URLs are not matched by the redirect rules by checking whether the part of the suffix after the `-` contains any numeric digits. While this check is not ideal, it should be good enough for our purpose, since the legacy URLs that we do want to redirect contain suffixes such as `-class`, `-function` and thus no numeric digits. [1]: https://circleci.com/gh/angular/angular/974345 [2]: https://circleci.com/gh/angular/angular/974346 PR Close #41842 PR Close #41854
1 parent 96f5c86 commit 61ad68a

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

aio/firebase.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,12 @@
9292
{"type": 301, "source": "/**/HTTP_PROVIDERS*", "destination": "/api/http/HttpModule"},
9393

9494
// URLs that use the old scheme of adding the type to the end (e.g. `SomeClass-class`)
95-
{"type": 301, "source": "/api/:package/:api-*", "destination": "/api/:package/:api"},
96-
{"type": 301, "source": "/api/:package/testing/index/:api-*", "destination": "/api/:package/testing/:api"},
97-
{"type": 301, "source": "/api/:package/testing/:api-*", "destination": "/api/:package/testing/:api"},
98-
{"type": 301, "source": "/api/upgrade/:package/index/:api-*", "destination": "/api/upgrade/:package/:api"},
99-
{"type": 301, "source": "/api/upgrade/:package/:api-*", "destination": "/api/upgrade/:package/:api"},
95+
// (Exclude disambiguated URLs that might be suffixed with `-\d+` (e.g. `SomeClass-1`))
96+
{"type": 301, "regex": "^/api/(?P<package>[^/]+)/(?P<api>[^/]+)-\\D*$", "destination": "/api/:package/:api"},
97+
{"type": 301, "regex": "^/api/(?P<package>[^/]+)/testing/index/(?P<api>[^/]+)$", "destination": "/api/:package/testing/:api"},
98+
{"type": 301, "regex": "^/api/(?P<package>[^/]+)/testing/(?P<api>[^/]+)-\\D*$", "destination": "/api/:package/testing/:api"},
99+
{"type": 301, "regex": "^/api/upgrade/(?P<package>[^/]+)/index/(?P<api>[^/]+)$", "destination": "/api/upgrade/:package/:api"},
100+
{"type": 301, "regex": "^/api/upgrade/(?P<package>[^/]+)/(?P<api>[^/]+)-\\D*$", "destination": "/api/upgrade/:package/:api"},
100101

101102
// URLs that use the old scheme before we moved the docs to the angular/angular repo
102103
{"type": 301, "source": "/docs/*/latest", "destination": "/docs"},

aio/ngsw-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"!/**/*__*/**",
7777
"!/**/stackblitz",
7878
"!/**/stackblitz.html",
79-
"!/api/*/**/*-*",
79+
"!/api/*/**/*-\\D{0,}",
8080
"!/api/**/AnimationStateDeclarationMetadata*",
8181
"!/api/**/CORE_DIRECTIVES*",
8282
"!/api/**/DirectiveMetadata*",

aio/tests/deployment/unit/testFirebaseRedirection.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,20 @@ describe('firebase.json redirect config', () => {
3333
});
3434
});
3535
});
36+
37+
it('should not redirect disambiguated URLs', () => {
38+
const redirector = getRedirector();
39+
40+
// Disambiguated URL.
41+
const url1 = '/api/core/Foo-0';
42+
expect(redirector.redirect(url1)).toBe(url1);
43+
44+
// Disambiguated URL.
45+
const url2 = '/api/core/BAR-1337';
46+
expect(redirector.redirect(url2)).toBe(url2);
47+
48+
// Non-disambiguated URL with dash.
49+
const url3 = '/api/core/baz-class';
50+
expect(redirector.redirect(url3)).toBe('/api/core/baz');
51+
});
3652
});

aio/tests/deployment/unit/testServiceWorkerRoutes.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,18 @@ describe('ServiceWorker navigation URLs', () => {
3535
navigationUrls.forEach(url => expect(isNavigationUrl(url)).toBeTruthy(url));
3636
nonNavigationUrls.forEach(url => expect(isNavigationUrl(url)).toBeFalsy(url));
3737
});
38+
39+
it('should treat disambiguated URLs as navigation URLs', () => {
40+
// Disambiguated URL.
41+
const url1 = '/api/core/Foo-0';
42+
expect(isNavigationUrl(url1)).toBeTruthy(url1);
43+
44+
// Disambiguated URL.
45+
const url2 = '/api/core/BAR-1337';
46+
expect(isNavigationUrl(url2)).toBeTruthy(url2);
47+
48+
// Non-disambiguated URL with dash.
49+
const url3 = '/api/core/baz-class';
50+
expect(isNavigationUrl(url3)).toBeFalsy(url3);
51+
});
3852
});

0 commit comments

Comments
 (0)