mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 17:00:55 +00:00
Merge pull request #6012 from mkqavi/fix/local-upload-url-encoding
Fix url encoding for local upload provider
This commit is contained in:
commit
f1116160ad
@ -13,7 +13,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"byte-size": "^6.2.0",
|
"byte-size": "^6.2.0",
|
||||||
"cropperjs": "^1.5.6",
|
"cropperjs": "^1.5.6",
|
||||||
"filenamify": "4.1.0",
|
|
||||||
"immer": "^6.0.2",
|
"immer": "^6.0.2",
|
||||||
"immutable": "^3.8.2",
|
"immutable": "^3.8.2",
|
||||||
"is-valid-domain": "0.0.14",
|
"is-valid-domain": "0.0.14",
|
||||||
|
@ -11,14 +11,14 @@ const path = require('path');
|
|||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const filenamify = require('filenamify');
|
const { nameToSlug } = require('strapi-utils');
|
||||||
const mime = require('mime-types');
|
const mime = require('mime-types');
|
||||||
|
|
||||||
const { bytesToKbytes } = require('../utils/file');
|
const { bytesToKbytes } = require('../utils/file');
|
||||||
|
|
||||||
const randomSuffix = () => crypto.randomBytes(5).toString('hex');
|
const randomSuffix = () => crypto.randomBytes(5).toString('hex');
|
||||||
const generateFileName = name => {
|
const generateFileName = name => {
|
||||||
const baseName = filenamify(name, { replacement: '_' }).replace(/\s/g, '_');
|
const baseName = nameToSlug(name, { separator: '_', lowercase: false });
|
||||||
|
|
||||||
return `${baseName}_${randomSuffix()}`;
|
return `${baseName}_${randomSuffix()}`;
|
||||||
};
|
};
|
||||||
|
@ -18,6 +18,22 @@ describe('Upload service', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Replaces reserved and unsafe characters for URLs and files in hash', () => {
|
||||||
|
const fileData = {
|
||||||
|
filename: 'File%&Näme\\<>:"|?*.png',
|
||||||
|
type: 'image/png',
|
||||||
|
size: 1000 * 1000,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(uploadService.formatFileInfo(fileData)).toMatchObject({
|
||||||
|
name: 'File%&Näme\\<>:"|?*',
|
||||||
|
hash: expect.stringContaining('File_and_Naeme'),
|
||||||
|
ext: '.png',
|
||||||
|
mime: 'image/png',
|
||||||
|
size: 1000,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('Overrides name with fileInfo', () => {
|
test('Overrides name with fileInfo', () => {
|
||||||
const fileData = {
|
const fileData = {
|
||||||
filename: 'File Name.png',
|
filename: 'File Name.png',
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
const slugify = require('@sindresorhus/slugify');
|
const slugify = require('@sindresorhus/slugify');
|
||||||
|
|
||||||
const nameToSlug = name => slugify(name, { separator: '-' });
|
const nameToSlug = (name, options = { separator: '-' }) => slugify(name, options);
|
||||||
|
|
||||||
const nameToCollectionName = name => slugify(name, { separator: '_' });
|
const nameToCollectionName = name => slugify(name, { separator: '_' });
|
||||||
|
|
||||||
|
28
yarn.lock
28
yarn.lock
@ -8033,20 +8033,6 @@ filed-mimefix@^0.1.3:
|
|||||||
dependencies:
|
dependencies:
|
||||||
mime "^1.4.0"
|
mime "^1.4.0"
|
||||||
|
|
||||||
filename-reserved-regex@^2.0.0:
|
|
||||||
version "2.0.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/filename-reserved-regex/-/filename-reserved-regex-2.0.0.tgz#abf73dfab735d045440abfea2d91f389ebbfa229"
|
|
||||||
integrity sha1-q/c9+rc10EVECr/qLZHzieu/oik=
|
|
||||||
|
|
||||||
filenamify@4.1.0:
|
|
||||||
version "4.1.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/filenamify/-/filenamify-4.1.0.tgz#54d110810ae74eebfe115c1b995bd07e03cf2184"
|
|
||||||
integrity sha512-KQV/uJDI9VQgN7sHH1Zbk6+42cD6mnQ2HONzkXUfPJ+K2FC8GZ1dpewbbHw0Sz8Tf5k3EVdHVayM4DoAwWlmtg==
|
|
||||||
dependencies:
|
|
||||||
filename-reserved-regex "^2.0.0"
|
|
||||||
strip-outer "^1.0.1"
|
|
||||||
trim-repeated "^1.0.0"
|
|
||||||
|
|
||||||
filesize@^4.1.2:
|
filesize@^4.1.2:
|
||||||
version "4.2.1"
|
version "4.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/filesize/-/filesize-4.2.1.tgz#ab1cb2069db5d415911c1a13e144c0e743bc89bc"
|
resolved "https://registry.yarnpkg.com/filesize/-/filesize-4.2.1.tgz#ab1cb2069db5d415911c1a13e144c0e743bc89bc"
|
||||||
@ -17573,13 +17559,6 @@ strip-json-comments@~2.0.1:
|
|||||||
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
|
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
|
||||||
integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo=
|
integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo=
|
||||||
|
|
||||||
strip-outer@^1.0.1:
|
|
||||||
version "1.0.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/strip-outer/-/strip-outer-1.0.1.tgz#b2fd2abf6604b9d1e6013057195df836b8a9d631"
|
|
||||||
integrity sha512-k55yxKHwaXnpYGsOzg4Vl8+tDrWylxDEpknGjhTiZB8dFRU5rTo9CAzeycivxV3s+zlTKwrs6WxMxR95n26kwg==
|
|
||||||
dependencies:
|
|
||||||
escape-string-regexp "^1.0.2"
|
|
||||||
|
|
||||||
strong-log-transformer@^2.0.0:
|
strong-log-transformer@^2.0.0:
|
||||||
version "2.1.0"
|
version "2.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/strong-log-transformer/-/strong-log-transformer-2.1.0.tgz#0f5ed78d325e0421ac6f90f7f10e691d6ae3ae10"
|
resolved "https://registry.yarnpkg.com/strong-log-transformer/-/strong-log-transformer-2.1.0.tgz#0f5ed78d325e0421ac6f90f7f10e691d6ae3ae10"
|
||||||
@ -18231,13 +18210,6 @@ trim-off-newlines@^1.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3"
|
resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3"
|
||||||
integrity sha1-n5up2e+odkw4dpi8v+sshI8RrbM=
|
integrity sha1-n5up2e+odkw4dpi8v+sshI8RrbM=
|
||||||
|
|
||||||
trim-repeated@^1.0.0:
|
|
||||||
version "1.0.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/trim-repeated/-/trim-repeated-1.0.0.tgz#e3646a2ea4e891312bf7eace6cfb05380bc01c21"
|
|
||||||
integrity sha1-42RqLqTokTEr9+rObPsFOAvAHCE=
|
|
||||||
dependencies:
|
|
||||||
escape-string-regexp "^1.0.2"
|
|
||||||
|
|
||||||
trim-trailing-lines@^1.0.0:
|
trim-trailing-lines@^1.0.0:
|
||||||
version "1.1.3"
|
version "1.1.3"
|
||||||
resolved "https://registry.yarnpkg.com/trim-trailing-lines/-/trim-trailing-lines-1.1.3.tgz#7f0739881ff76657b7776e10874128004b625a94"
|
resolved "https://registry.yarnpkg.com/trim-trailing-lines/-/trim-trailing-lines-1.1.3.tgz#7f0739881ff76657b7776e10874128004b625a94"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user