Skip to content

Commit

Permalink
fix: invalid contentDisposition header value (#1111)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusmarminge authored Jan 1, 2025
1 parent 1d7398a commit d1f66f3
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 56 deletions.
27 changes: 0 additions & 27 deletions packages/shared/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
UnknownFileTypeError,
} from "./tagged-errors";
import type {
ContentDisposition,
ExpandedRouteConfig,
FileProperties,
FileRouterInputConfig,
Expand Down Expand Up @@ -194,32 +193,6 @@ export function filterDefinedObjectValues<T>(
);
}

/** construct content-disposition header according to RFC 6266 section 4.1
* https://www.rfc-editor.org/rfc/rfc6266#section-4.1
*
* @example
* contentDisposition("inline", 'my "special" file,name.pdf');
* // => "inline; filename="my \"special\" file\,name.pdf"; filename*=UTF-8''my%20%22special%22%20file%2Cname.pdf"
*/
export function contentDisposition(
contentDisposition: ContentDisposition,
fileName: string,
) {
// Encode the filename for the legacy parameter
const legacyFileName = fileName.replace(/[",\\']/g, "\\$&");

//UTF-8 encode for the extended parameter (RFC 5987)
const utf8FileName = encodeURIComponent(fileName)
.replace(/[')(]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`)
.replace(/\*/g, "%2A");

return [
contentDisposition,
`filename="${legacyFileName}"`,
`filename*=UTF-8''${utf8FileName}`,
].join("; ");
}

export function semverLite(required: string, toCheck: string) {
// Pull out numbers from strings like `6.0.0`, `^6.4`, `~6.4.0`
const semverRegex = /(\d+)\.?(\d+)?\.?(\d+)?/;
Expand Down
29 changes: 0 additions & 29 deletions packages/shared/test/utils.test.ts

This file was deleted.

0 comments on commit d1f66f3

Please sign in to comment.