Repository navigation
Decide in _resolve whether a ? is part of a path or starts a query
#36627
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
Open
robobun
wants to merge
32
commits into
main
Choose a base branch
from
farm/f2eb0668/fix-question-mark-in-path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
2764861
resolver: don't treat '?' in a directory name as a query-string separ…
robobun 2ef1185
address review: skip only '?/' sequences, add ImportMetaObject, extra…
robobun 9ea7307
trim doc comments (comment-cop)
robobun 33285f4
trim doc comment to one line
robobun 795a109
apply ?/ skip to CommonJS.ts .node gate, cfg-gate on Windows
robobun 665c21e
test: run 07928 subprocess tests concurrently
robobun 3e2d29e
test: add positive assertions in .node and ?/ trade-off tests
robobun 81a32a3
ci: retrigger
robobun c458e97
Merge main and remove the '?/' rule
robobun ecd30d2
Decide in _resolve what a '?' in a module specifier is, and carry the…
robobun c10a6d3
import.meta, the .node checks and bun's own imports read where the pa…
robobun 9cb0f19
Test a '?' in a file or folder name in import-query.test.ts
robobun da9fe91
Test bun test in a folder with '?' in its name
robobun 332b645
Test bun -e in a working directory with '?' in its name
robobun 6fa1de1
Test import.meta of a module in a folder with '?' in its name
robobun e120caf
Test a worker whose file is in a folder with '?' in its name
robobun 4115112
Test plugins with an importer and an answer in a folder with '?' in i…
robobun e410e39
Test a macro and a cron script in a folder with '?' in its name
robobun 3b3e8ae
Test an HTML entry point in a folder with '?' in its name
robobun 3d46c2c
Keep the '?' tests in files that pass in a debug build
robobun ad9c1c5
Format
robobun e55e50c
Test bunfig serve plugins in a folder with '?' in its name
robobun 268b7f9
A name right in the importing folder needs no path join, and a module…
robobun df4a7ed
Test a query after a path with '?' that is not ASCII
robobun f3e51d5
Merge remote-tracking branch 'origin/main' into farm/f2eb0668/fix-que…
robobun e0afafb
Read every string that is not an ES specifier as a path with a query …
robobun 3ee0b87
Keep the macro and cron imports as they are on Windows
robobun bafe680
Record the key of a path with '?' in _resolve, and scan a key with no…
robobun e4f170c
Ask for the path length of a required id only when it can name an addon
robobun 3e546b8
Ask the folder cache about a late folder only for an absolute path
robobun b2739ea
Look for '.node' in a required id with one call, as before
robobun 369c978
Declare the return of $internalRequire as any
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,95 @@ | ||
| // https://github.com/oven-sh/bun/issues/7928 | ||
| // A '?' in a directory name was being treated as a query-string separator by | ||
| // the module resolver/loader, so files under that directory could not be | ||
| // loaded. Windows does not allow '?' in path names, so these tests only run on | ||
| // POSIX. | ||
| import { expect, test } from "bun:test"; | ||
| import { bunEnv, bunExe, isWindows, normalizeBunSnapshot, tempDir } from "harness"; | ||
|
|
||
| test.skipIf(isWindows)("`bun test` runs tests from a directory whose name contains '?'", async () => { | ||
|
robobun marked this conversation as resolved.
Resolved
|
||
| using dir = tempDir("issue-7928-test", { | ||
| "some-path?/my.test.js": ` | ||
| import { test, expect } from "bun:test"; | ||
| test("inside dir with ?", () => { expect(1 + 1).toBe(2); }); | ||
| `, | ||
| }); | ||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "test", "my.test.js"], | ||
| env: bunEnv, | ||
| cwd: String(dir), | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| const out = normalizeBunSnapshot(stdout + stderr, dir); | ||
| expect(out).toContain("(pass) inside dir with ?"); | ||
| expect(out).toContain("1 pass"); | ||
| expect(out).not.toContain("Module not found"); | ||
| expect(out).not.toContain("FileNotFound"); | ||
| expect(exitCode).toBe(0); | ||
| }); | ||
|
|
||
| test.skipIf(isWindows)("`bun <file>` runs a file under a directory whose name contains '?'", async () => { | ||
| using dir = tempDir("issue-7928-run", { | ||
| "some-path?/main.js": `console.log("ran from dir with ?");`, | ||
| }); | ||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "./some-path?/main.js"], | ||
| env: bunEnv, | ||
| cwd: String(dir), | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stderr).toBe(""); | ||
| expect(stdout).toBe("ran from dir with ?\n"); | ||
| expect(exitCode).toBe(0); | ||
| }); | ||
|
|
||
| test.skipIf(isWindows)("import resolves across a directory whose name contains '?'", async () => { | ||
| using dir = tempDir("issue-7928-import", { | ||
| "dir?/dep.js": `export const value = 42;`, | ||
| "dir?/entry.js": ` | ||
| import { value } from "./dep.js"; | ||
| console.log(JSON.stringify({ value, url: import.meta.url })); | ||
| `, | ||
| }); | ||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "./dir?/entry.js"], | ||
| env: bunEnv, | ||
| cwd: String(dir), | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stderr).toBe(""); | ||
| const { value, url } = JSON.parse(stdout.trim()); | ||
| expect(value).toBe(42); | ||
| expect(decodeURIComponent(url)).toEndWith("dir?/entry.js"); | ||
| expect(exitCode).toBe(0); | ||
| }); | ||
|
Check failure on line 70 in test/regression/issue/07928.test.ts
|
||
|
robobun marked this conversation as resolved.
Resolved
|
||
|
|
||
| test.skipIf(isWindows)("query-string suffix still works when a parent directory contains '?'", async () => { | ||
| using dir = tempDir("issue-7928-query", { | ||
| "dir?/dep.js": `export const url = import.meta.url;`, | ||
| "dir?/entry.js": ` | ||
| const a = await import("./dep.js"); | ||
| const b = await import("./dep.js?v=1"); | ||
| console.log(JSON.stringify({ a: a.url, b: b.url, distinct: a !== b })); | ||
| `, | ||
| }); | ||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "./dir?/entry.js"], | ||
| env: bunEnv, | ||
| cwd: String(dir), | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stderr).toBe(""); | ||
| const { a, b, distinct } = JSON.parse(stdout.trim()); | ||
| expect(decodeURIComponent(a)).toEndWith("dir?/dep.js"); | ||
| expect(decodeURIComponent(b)).toEndWith("dir?/dep.js?v=1"); | ||
| expect(distinct).toBe(true); | ||
| expect(exitCode).toBe(0); | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.