@fastify/static 7.0.3 → 7.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +0 -0
- package/.gitattributes +0 -0
- package/.github/dependabot.yml +0 -0
- package/.github/stale.yml +0 -0
- package/.github/workflows/ci.yml +0 -0
- package/.taprc +0 -0
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/example/public/.hidden/sample.json +0 -0
- package/example/public/images/sample.jpg +0 -0
- package/example/public/index.css +0 -0
- package/example/public/index.html +0 -0
- package/example/public/index.js +0 -0
- package/example/public2/test.css +0 -0
- package/example/public2/test.html +0 -0
- package/example/server-compress.js +0 -0
- package/example/server-dir-list.js +0 -0
- package/example/server-hidden-file.js +0 -0
- package/example/server.js +0 -0
- package/index.js +2 -1
- package/lib/dirList.js +1 -1
- package/package.json +1 -1
- package/test/content-type/binary +0 -0
- package/test/content-type/binary.br +0 -0
- package/test/content-type/index.css +0 -0
- package/test/content-type/index.css.br +0 -0
- package/test/content-type/index.html +0 -0
- package/test/content-type/index.html.br +0 -0
- package/test/content-type/sample.jpg +0 -0
- package/test/content-type/test.txt +0 -0
- package/test/content-type/test.txt.br +0 -0
- package/test/content-type.test.js +0 -0
- package/test/dir-list.test.js +8 -6
- package/test/static/.example +0 -0
- package/test/static/100%.txt +1 -0
- package/test/static/a .md +0 -0
- package/test/static/deep/path/for/test/index.html +0 -0
- package/test/static/deep/path/for/test/purpose/foo.html +0 -0
- package/test/static/foo.html +0 -0
- package/test/static/foobar.html +0 -0
- package/test/static/index.css +0 -0
- package/test/static/index.html +0 -0
- package/test/static/shallow/sample.jpg +0 -0
- package/test/static-dotfiles/.aaa +0 -0
- package/test/static-dotfiles/dir/index.html +0 -0
- package/test/static-dotfiles/test.txt +0 -0
- package/test/static-encode/[...]/a .md +0 -0
- package/test/static-hidden/.hidden/sample.json +0 -0
- package/test/static-pre-compressed/all-three.html +0 -0
- package/test/static-pre-compressed/all-three.html.br +0 -0
- package/test/static-pre-compressed/all-three.html.gz +0 -0
- package/test/static-pre-compressed/dir/index.html +0 -0
- package/test/static-pre-compressed/dir/index.html.br +0 -0
- package/test/static-pre-compressed/dir-gz/index.html +0 -0
- package/test/static-pre-compressed/dir-gz/index.html.gz +0 -0
- package/test/static-pre-compressed/empty/.gitkeep +0 -0
- package/test/static-pre-compressed/gzip-only.html +0 -0
- package/test/static-pre-compressed/gzip-only.html.gz +0 -0
- package/test/static-pre-compressed/index.html +0 -0
- package/test/static-pre-compressed/index.html.br +0 -0
- package/test/static-pre-compressed/sample.jpg +0 -0
- package/test/static-pre-compressed/sample.jpg.br +0 -0
- package/test/static-pre-compressed/uncompressed.html +0 -0
- package/test/static-symbolic-link/origin/subdir/subdir/index.html +0 -0
- package/test/static.test.js +27 -0
- package/test/static2/bar.html +0 -0
- package/test/static2/index.html +0 -0
- package/tsconfig.eslint.json +0 -0
- package/types/index.d.ts +0 -0
- package/types/index.test-d.ts +0 -0
package/.eslintrc.json
CHANGED
|
File without changes
|
package/.gitattributes
CHANGED
|
File without changes
|
package/.github/dependabot.yml
CHANGED
|
File without changes
|
package/.github/stale.yml
CHANGED
|
File without changes
|
package/.github/workflows/ci.yml
CHANGED
|
File without changes
|
package/.taprc
CHANGED
|
File without changes
|
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/example/public/index.css
CHANGED
|
File without changes
|
|
File without changes
|
package/example/public/index.js
CHANGED
|
File without changes
|
package/example/public2/test.css
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/example/server.js
CHANGED
|
File without changes
|
package/index.js
CHANGED
|
@@ -221,7 +221,8 @@ async function fastifyStatic (fastify, opts) {
|
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
|
|
224
|
+
// `send(..., path, ...)` will URI-decode path so we pass an encoded path here
|
|
225
|
+
const stream = send(request.raw, encodeURI(pathnameForSend), options)
|
|
225
226
|
let resolvedFilename
|
|
226
227
|
stream.on('file', function (file) {
|
|
227
228
|
resolvedFilename = file
|
package/lib/dirList.js
CHANGED
|
@@ -149,7 +149,7 @@ const dirList = {
|
|
|
149
149
|
route = path.normalize(path.join(route, '..'))
|
|
150
150
|
}
|
|
151
151
|
return {
|
|
152
|
-
href: path.join(prefix, route, entry.name).replace(/\\/gu, '/'),
|
|
152
|
+
href: encodeURI(path.join(prefix, route, entry.name).replace(/\\/gu, '/')),
|
|
153
153
|
name: entry.name,
|
|
154
154
|
stats: entry.stats,
|
|
155
155
|
extendedInfo: entry.extendedInfo
|
package/package.json
CHANGED
package/test/content-type/binary
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/test/dir-list.test.js
CHANGED
|
@@ -154,7 +154,7 @@ t.test('dir list, custom options', t => {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
const route = '/public/'
|
|
157
|
-
const content = { dirs: ['deep', 'shallow'], files: ['.example', 'a .md', 'foo.html', 'foobar.html', 'index.css', 'index.html'] }
|
|
157
|
+
const content = { dirs: ['deep', 'shallow'], files: ['.example', '100%.txt', 'a .md', 'foo.html', 'foobar.html', 'index.css', 'index.html'] }
|
|
158
158
|
|
|
159
159
|
helper.arrange(t, options, (url) => {
|
|
160
160
|
t.test(route, t => {
|
|
@@ -205,7 +205,8 @@ t.test('dir list html format', t => {
|
|
|
205
205
|
</ul>
|
|
206
206
|
<ul>
|
|
207
207
|
<li><a href="/public/.example" target="_blank">.example</a></li>
|
|
208
|
-
<li><a href="/public/
|
|
208
|
+
<li><a href="/public/100%25.txt" target="_blank">100%.txt</a></li>
|
|
209
|
+
<li><a href="/public/a%20.md" target="_blank">a .md</a></li>
|
|
209
210
|
<li><a href="/public/foo.html" target="_blank">foo.html</a></li>
|
|
210
211
|
<li><a href="/public/foobar.html" target="_blank">foobar.html</a></li>
|
|
211
212
|
<li><a href="/public/index.css" target="_blank">index.css</a></li>
|
|
@@ -236,7 +237,8 @@ t.test('dir list html format', t => {
|
|
|
236
237
|
</ul>
|
|
237
238
|
<ul>
|
|
238
239
|
<li><a href="/public/.example" target="_blank">.example</a></li>
|
|
239
|
-
<li><a href="/public/
|
|
240
|
+
<li><a href="/public/100%25.txt" target="_blank">100%.txt</a></li>
|
|
241
|
+
<li><a href="/public/a%20.md" target="_blank">a .md</a></li>
|
|
240
242
|
<li><a href="/public/foo.html" target="_blank">foo.html</a></li>
|
|
241
243
|
<li><a href="/public/foobar.html" target="_blank">foobar.html</a></li>
|
|
242
244
|
<li><a href="/public/index.css" target="_blank">index.css</a></li>
|
|
@@ -492,7 +494,7 @@ t.test('json format with url parameter format', t => {
|
|
|
492
494
|
}
|
|
493
495
|
}
|
|
494
496
|
const route = '/public/'
|
|
495
|
-
const jsonContent = { dirs: ['deep', 'shallow'], files: ['.example', 'a .md', 'foo.html', 'foobar.html', 'index.css', 'index.html'] }
|
|
497
|
+
const jsonContent = { dirs: ['deep', 'shallow'], files: ['.example', '100%.txt', 'a .md', 'foo.html', 'foobar.html', 'index.css', 'index.html'] }
|
|
496
498
|
|
|
497
499
|
helper.arrange(t, options, (url) => {
|
|
498
500
|
simple.concat({
|
|
@@ -539,7 +541,7 @@ t.test('json format with url parameter format and without render option', t => {
|
|
|
539
541
|
}
|
|
540
542
|
}
|
|
541
543
|
const route = '/public/'
|
|
542
|
-
const jsonContent = { dirs: ['deep', 'shallow'], files: ['.example', 'a .md', 'foo.html', 'foobar.html', 'index.css', 'index.html'] }
|
|
544
|
+
const jsonContent = { dirs: ['deep', 'shallow'], files: ['.example', '100%.txt', 'a .md', 'foo.html', 'foobar.html', 'index.css', 'index.html'] }
|
|
543
545
|
|
|
544
546
|
helper.arrange(t, options, (url) => {
|
|
545
547
|
simple.concat({
|
|
@@ -588,7 +590,7 @@ t.test('html format with url parameter format', t => {
|
|
|
588
590
|
}
|
|
589
591
|
}
|
|
590
592
|
const route = '/public/'
|
|
591
|
-
const jsonContent = { dirs: ['deep', 'shallow'], files: ['.example', 'a .md', 'foo.html', 'foobar.html', 'index.css', 'index.html'] }
|
|
593
|
+
const jsonContent = { dirs: ['deep', 'shallow'], files: ['.example', '100%.txt', 'a .md', 'foo.html', 'foobar.html', 'index.css', 'index.html'] }
|
|
592
594
|
|
|
593
595
|
helper.arrange(t, options, (url) => {
|
|
594
596
|
simple.concat({
|
package/test/static/.example
CHANGED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
100%
|
package/test/static/a .md
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/test/static/foo.html
CHANGED
|
File without changes
|
package/test/static/foobar.html
CHANGED
|
File without changes
|
package/test/static/index.css
CHANGED
|
File without changes
|
package/test/static/index.html
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/test/static.test.js
CHANGED
|
@@ -3963,6 +3963,33 @@ t.test(
|
|
|
3963
3963
|
}
|
|
3964
3964
|
)
|
|
3965
3965
|
|
|
3966
|
+
t.test(
|
|
3967
|
+
'serves files with % in the filename',
|
|
3968
|
+
async (t) => {
|
|
3969
|
+
t.plan(2)
|
|
3970
|
+
|
|
3971
|
+
const txtContent = fs.readFileSync(path.join(__dirname, 'static', '100%.txt'), 'utf-8')
|
|
3972
|
+
|
|
3973
|
+
const pluginOptions = {
|
|
3974
|
+
root: url.pathToFileURL(path.join(__dirname, '/static')),
|
|
3975
|
+
wildcard: false
|
|
3976
|
+
}
|
|
3977
|
+
|
|
3978
|
+
const fastify = Fastify()
|
|
3979
|
+
|
|
3980
|
+
fastify.register(fastifyStatic, pluginOptions)
|
|
3981
|
+
const response = await fastify.inject({
|
|
3982
|
+
method: 'GET',
|
|
3983
|
+
url: '100%25.txt',
|
|
3984
|
+
headers: {
|
|
3985
|
+
'accept-encoding': '*, *'
|
|
3986
|
+
}
|
|
3987
|
+
})
|
|
3988
|
+
t.equal(response.statusCode, 200)
|
|
3989
|
+
t.same(response.body, txtContent)
|
|
3990
|
+
}
|
|
3991
|
+
)
|
|
3992
|
+
|
|
3966
3993
|
t.test('content-length in head route should not return zero when using wildcard', t => {
|
|
3967
3994
|
t.plan(6)
|
|
3968
3995
|
|
package/test/static2/bar.html
CHANGED
|
File without changes
|
package/test/static2/index.html
CHANGED
|
File without changes
|
package/tsconfig.eslint.json
CHANGED
|
File without changes
|
package/types/index.d.ts
CHANGED
|
File without changes
|
package/types/index.test-d.ts
CHANGED
|
File without changes
|