Skip to content

Commit 2f20855

Browse files
committed
Set the busboy option defParamCharset to utf8.
Fixes #328 .
1 parent 1d46b18 commit 2f20855

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Patch
66

7+
- Support non `latin1` characters in file names by setting the [`busboy`](https://npm.im/busboy) option `defParamCharset` to `utf8`, fixing [#328](https://github.com/jaydenseric/graphql-upload/issues/328).
78
- Removed a redundant `@ts-ignore` comment.
89

910
## 16.0.0

processRequest.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export default function processRequest(
5757

5858
const parser = busboy({
5959
headers: request.headers,
60+
defParamCharset: "utf8",
6061
limits: {
6162
fieldSize: maxFieldSize,
6263
fields: 2, // Only operations and map.

processRequest.test.mjs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default (tests) => {
5555
});
5656

5757
tests.add(
58-
"`processRequest` with a single file and default `createReadStream` options.",
58+
"`processRequest` with a single file, default `createReadStream` options, file name chars `latin1`.",
5959
async () => {
6060
let serverError;
6161

@@ -113,6 +113,67 @@ export default (tests) => {
113113
}
114114
);
115115

116+
tests.add(
117+
"`processRequest` with a single file, default `createReadStream` options, file name chars non `latin1`.",
118+
async () => {
119+
const fileName = "你好.txt";
120+
121+
let serverError;
122+
123+
const server = createServer(async (request, response) => {
124+
try {
125+
const operation =
126+
/**
127+
* @type {{
128+
* variables: {
129+
* file: Upload,
130+
* },
131+
* }}
132+
*/
133+
(await processRequest(request, response));
134+
135+
ok(operation.variables.file instanceof Upload);
136+
137+
const upload = await operation.variables.file.promise;
138+
139+
strictEqual(upload.filename, fileName);
140+
strictEqual(upload.mimetype, "text/plain");
141+
strictEqual(upload.encoding, "7bit");
142+
143+
const stream = upload.createReadStream();
144+
145+
ok(stream instanceof ReadStream);
146+
strictEqual(stream.readableEncoding, null);
147+
strictEqual(stream.readableHighWaterMark, 16384);
148+
strictEqual(await streamToString(stream), "a");
149+
} catch (error) {
150+
serverError = error;
151+
} finally {
152+
response.end();
153+
}
154+
});
155+
156+
const { port, close } = await listen(server);
157+
158+
try {
159+
const body = new FormData();
160+
161+
body.append(
162+
"operations",
163+
JSON.stringify({ variables: { file: null } })
164+
);
165+
body.append("map", JSON.stringify({ 1: ["variables.file"] }));
166+
body.append("1", new File(["a"], fileName, { type: "text/plain" }));
167+
168+
await fetch(`http://localhost:${port}`, { method: "POST", body });
169+
170+
if (serverError) throw serverError;
171+
} finally {
172+
close();
173+
}
174+
}
175+
);
176+
116177
tests.add(
117178
"`processRequest` with a single file and custom `createReadStream` options.",
118179
async () => {

0 commit comments

Comments
 (0)