New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Underscore Handling Fixes #47581
Merged
Merged
Underscore Handling Fixes #47581
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ed9fa66
fix: handle case where absolute path contains a _
wyattjoh 2a394f2
Merge branch 'canary' into wyattjoh/fix-absolute-underscore-matching
wyattjoh 152b0b5
fix: switch path to shared path module
wyattjoh fdf746c
fix: cleanup for built normalizers
wyattjoh 6d312c9
Merge branch 'canary' into wyattjoh/fix-absolute-underscore-matching
wyattjoh 7734829
fix: move metadata config
wyattjoh File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/next/src/server/future/normalizers/built/app/app-bundle-path-normalizer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Normalizers } from '../../normalizers' | ||
import { Normalizer } from '../../normalizer' | ||
import { PrefixingNormalizer } from '../../prefixing-normalizer' | ||
|
||
export class AppBundlePathNormalizer extends PrefixingNormalizer { | ||
constructor() { | ||
super('app') | ||
} | ||
|
||
public normalize(page: string): string { | ||
return super.normalize(page) | ||
} | ||
} | ||
|
||
export class DevAppBundlePathNormalizer extends Normalizers { | ||
constructor(pageNormalizer: Normalizer) { | ||
super([ | ||
// This should normalize the filename to a page. | ||
pageNormalizer, | ||
// Normalize the app page to a pathname. | ||
new AppBundlePathNormalizer(), | ||
]) | ||
} | ||
|
||
public normalize(filename: string): string { | ||
return super.normalize(filename) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/next/src/server/future/normalizers/built/app/app-filename-normalizer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { SERVER_DIRECTORY } from '../../../../../shared/lib/constants' | ||
import { PrefixingNormalizer } from '../../prefixing-normalizer' | ||
|
||
export class AppFilenameNormalizer extends PrefixingNormalizer { | ||
constructor(distDir: string) { | ||
super(distDir, SERVER_DIRECTORY) | ||
} | ||
|
||
public normalize(manifestFilename: string): string { | ||
return super.normalize(manifestFilename) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/next/src/server/future/normalizers/built/app/app-page-normalizer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { AbsoluteFilenameNormalizer } from '../../absolute-filename-normalizer' | ||
|
||
/** | ||
* DevAppPageNormalizer is a normalizer that is used to normalize a pathname | ||
* to a page in the `app` directory. | ||
*/ | ||
export class DevAppPageNormalizer extends AbsoluteFilenameNormalizer { | ||
constructor(appDir: string, extensions: ReadonlyArray<string>) { | ||
super(appDir, extensions, 'app') | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/next/src/server/future/normalizers/built/app/app-pathname-normalizer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { normalizeAppPath } from '../../../../../shared/lib/router/utils/app-paths' | ||
import { Normalizers } from '../../normalizers' | ||
import { wrapNormalizerFn } from '../../wrap-normalizer-fn' | ||
import { UnderscoreNormalizer } from '../../underscore-normalizer' | ||
import { Normalizer } from '../../normalizer' | ||
|
||
export class AppPathnameNormalizer extends Normalizers { | ||
constructor() { | ||
super([ | ||
// The pathname to match should have the trailing `/page` and other route | ||
// group information stripped from it. | ||
wrapNormalizerFn(normalizeAppPath), | ||
// The page should have the `%5F` characters replaced with `_` characters. | ||
new UnderscoreNormalizer(), | ||
]) | ||
} | ||
|
||
public normalize(page: string): string { | ||
return super.normalize(page) | ||
} | ||
} | ||
|
||
export class DevAppPathnameNormalizer extends Normalizers { | ||
constructor(pageNormalizer: Normalizer) { | ||
super([ | ||
// This should normalize the filename to a page. | ||
pageNormalizer, | ||
// Normalize the app page to a pathname. | ||
new AppPathnameNormalizer(), | ||
]) | ||
} | ||
|
||
public normalize(filename: string): string { | ||
return super.normalize(filename) | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
packages/next/src/server/future/normalizers/built/app/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
AppBundlePathNormalizer, | ||
DevAppBundlePathNormalizer, | ||
} from './app-bundle-path-normalizer' | ||
import { AppFilenameNormalizer } from './app-filename-normalizer' | ||
import { DevAppPageNormalizer } from './app-page-normalizer' | ||
import { | ||
AppPathnameNormalizer, | ||
DevAppPathnameNormalizer, | ||
} from './app-pathname-normalizer' | ||
|
||
export class AppNormalizers { | ||
public readonly filename: AppFilenameNormalizer | ||
public readonly pathname: AppPathnameNormalizer | ||
public readonly bundlePath: AppBundlePathNormalizer | ||
|
||
constructor(distDir: string) { | ||
this.filename = new AppFilenameNormalizer(distDir) | ||
this.pathname = new AppPathnameNormalizer() | ||
this.bundlePath = new AppBundlePathNormalizer() | ||
} | ||
} | ||
|
||
export class DevAppNormalizers { | ||
public readonly page: DevAppPageNormalizer | ||
public readonly pathname: DevAppPathnameNormalizer | ||
public readonly bundlePath: DevAppBundlePathNormalizer | ||
|
||
constructor(appDir: string, extensions: ReadonlyArray<string>) { | ||
this.page = new DevAppPageNormalizer(appDir, extensions) | ||
this.pathname = new DevAppPathnameNormalizer(this.page) | ||
this.bundlePath = new DevAppBundlePathNormalizer(this.page) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/next/src/server/future/normalizers/built/pages/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
DevPagesBundlePathNormalizer, | ||
PagesBundlePathNormalizer, | ||
} from './pages-bundle-path-normalizer' | ||
import { PagesFilenameNormalizer } from './pages-filename-normalizer' | ||
import { DevPagesPageNormalizer } from './pages-page-normalizer' | ||
import { DevPagesPathnameNormalizer } from './pages-pathname-normalizer' | ||
|
||
export class PagesNormalizers { | ||
public readonly filename: PagesFilenameNormalizer | ||
public readonly bundlePath: PagesBundlePathNormalizer | ||
|
||
constructor(distDir: string) { | ||
this.filename = new PagesFilenameNormalizer(distDir) | ||
this.bundlePath = new PagesBundlePathNormalizer() | ||
|
||
// You'd think that we'd require a `pathname` normalizer here, but for | ||
// `/pages` we have to handle i18n routes, which means that we need to | ||
// analyze the page path to determine the locale prefix and it's locale. | ||
} | ||
} | ||
|
||
export class DevPagesNormalizers { | ||
public readonly page: DevPagesPageNormalizer | ||
public readonly pathname: DevPagesPathnameNormalizer | ||
public readonly bundlePath: DevPagesBundlePathNormalizer | ||
|
||
constructor(pagesDir: string, extensions: ReadonlyArray<string>) { | ||
this.page = new DevPagesPageNormalizer(pagesDir, extensions) | ||
this.pathname = new DevPagesPathnameNormalizer(pagesDir, extensions) | ||
this.bundlePath = new DevPagesBundlePathNormalizer(this.page) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/next/src/server/future/normalizers/built/pages/pages-bundle-path-normalizer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { normalizePagePath } from '../../../../../shared/lib/page-path/normalize-page-path' | ||
import { Normalizer } from '../../normalizer' | ||
import { Normalizers } from '../../normalizers' | ||
import { PrefixingNormalizer } from '../../prefixing-normalizer' | ||
import { wrapNormalizerFn } from '../../wrap-normalizer-fn' | ||
|
||
export class PagesBundlePathNormalizer extends Normalizers { | ||
constructor() { | ||
super([ | ||
// The bundle path should have the trailing `/index` stripped from | ||
// it. | ||
wrapNormalizerFn(normalizePagePath), | ||
// The page should prefixed with `pages/`. | ||
new PrefixingNormalizer('pages'), | ||
]) | ||
} | ||
|
||
public normalize(page: string): string { | ||
return super.normalize(page) | ||
} | ||
} | ||
|
||
export class DevPagesBundlePathNormalizer extends Normalizers { | ||
constructor(pagesNormalizer: Normalizer) { | ||
super([ | ||
// This should normalize the filename to a page. | ||
pagesNormalizer, | ||
// Normalize the app page to a pathname. | ||
new PagesBundlePathNormalizer(), | ||
]) | ||
} | ||
|
||
public normalize(filename: string): string { | ||
return super.normalize(filename) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/next/src/server/future/normalizers/built/pages/pages-filename-normalizer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { SERVER_DIRECTORY } from '../../../../../shared/lib/constants' | ||
import { PrefixingNormalizer } from '../../prefixing-normalizer' | ||
|
||
export class PagesFilenameNormalizer extends PrefixingNormalizer { | ||
constructor(distDir: string) { | ||
super(distDir, SERVER_DIRECTORY) | ||
} | ||
|
||
public normalize(manifestFilename: string): string { | ||
return super.normalize(manifestFilename) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/next/src/server/future/normalizers/built/pages/pages-page-normalizer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { AbsoluteFilenameNormalizer } from '../../absolute-filename-normalizer' | ||
|
||
export class DevPagesPageNormalizer extends AbsoluteFilenameNormalizer { | ||
constructor(pagesDir: string, extensions: ReadonlyArray<string>) { | ||
super(pagesDir, extensions, 'pages') | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/next/src/server/future/normalizers/built/pages/pages-pathname-normalizer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { AbsoluteFilenameNormalizer } from '../../absolute-filename-normalizer' | ||
|
||
export class DevPagesPathnameNormalizer extends AbsoluteFilenameNormalizer { | ||
constructor(pagesDir: string, extensions: ReadonlyArray<string>) { | ||
super(pagesDir, extensions, 'pages') | ||
} | ||
} |
8 changes: 6 additions & 2 deletions
8
packages/next/src/server/future/normalizers/prefixing-normalizer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
packages/next/src/server/future/normalizers/underscore-normalizer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Normalizer } from './normalizer' | ||
|
||
/** | ||
* UnderscoreNormalizer replaces all instances of %5F with _. | ||
*/ | ||
export class UnderscoreNormalizer implements Normalizer { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Java-ism strikes again 😂 |
||
public normalize(pathname: string): string { | ||
return pathname.replace(/%5F/g, '_') | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use the
pageName
instead of thefileName
because thefileName
includes path parts outside the Next.js directory.