-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
fix: Preserve UTF-8 GraphQL upload filenames with latest graphql-upload #10478
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
coratgerl
wants to merge
10
commits into
parse-community:alpha
Choose a base branch
from
coratgerl:fix-file-encodage
base: alpha
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.
+757
−58
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2b87ddb
fix: preserve UTF-8 GraphQL upload filenames with latest graphql-upload
coratgerl 5a08112
fix: ci
coratgerl 063b85c
fix: correct GraphQL file upload proxy error handling
coratgerl 8193231
fix: normalize Unicode filenames for file storage lookups
coratgerl 7b2bc6e
fix: harden filename validation for non-string and path inputs
coratgerl d2d2651
fix: feedbacks
coratgerl dfdaae4
feat: more tests
coratgerl 484a48f
fix: test
coratgerl 3cfd9e0
feat: merge
coratgerl 8856dec
feat: more test
coratgerl 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,51 @@ | ||
| // Cache the dynamic imports so the ESM-only graphql-upload modules are | ||
| // resolved once and then reused by both schema loading and request handling. | ||
| let graphqlUploadModulesPromise; | ||
|
|
||
| const loadGraphQLUploadModules = async () => { | ||
| if (!graphqlUploadModulesPromise) { | ||
| graphqlUploadModulesPromise = Promise.all([ | ||
| import('graphql-upload/GraphQLUpload.mjs'), | ||
| import('graphql-upload/processRequest.mjs'), | ||
| ]).then(([{ default: GraphQLUpload }, { default: processRequest }]) => ({ | ||
| GraphQLUpload, | ||
| processRequest, | ||
| })); | ||
| } | ||
|
|
||
| return graphqlUploadModulesPromise; | ||
| }; | ||
|
|
||
| // Expose the Upload scalar lazily so the rest of Parse Server can stay on the | ||
| // current module system while graphql-upload is now ESM-only. | ||
| const getGraphQLUpload = async () => { | ||
| const { GraphQLUpload } = await loadGraphQLUploadModules(); | ||
| return GraphQLUpload; | ||
| }; | ||
|
|
||
| const createGraphQLUploadMiddleware = options => { | ||
| const uploadOptions = { | ||
| ...options, | ||
| // Decode multipart filename parameters as UTF-8 so filenames like | ||
| // "cafe.txt" with accents don't arrive as mojibake. | ||
| defParamCharset: 'utf8', | ||
| }; | ||
|
|
||
| return async (req, res, next) => { | ||
| if (!req.is || !req.is('multipart/form-data')) { | ||
| return next(); | ||
| } | ||
|
|
||
| try { | ||
| const { processRequest } = await loadGraphQLUploadModules(); | ||
| // graphql-upload parses the multipart body and populates req.body with | ||
| // Upload promises before Apollo handles the GraphQL operation. | ||
| req.body = await processRequest(req, res, uploadOptions); | ||
| return next(); | ||
| } catch (error) { | ||
| return next(error); | ||
| } | ||
| }; | ||
| }; | ||
|
|
||
| export { createGraphQLUploadMiddleware, getGraphQLUpload }; |
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
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.