@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.
Files changed (70) hide show
  1. package/.eslintrc.json +0 -0
  2. package/.gitattributes +0 -0
  3. package/.github/dependabot.yml +0 -0
  4. package/.github/stale.yml +0 -0
  5. package/.github/workflows/ci.yml +0 -0
  6. package/.taprc +0 -0
  7. package/LICENSE +0 -0
  8. package/README.md +0 -0
  9. package/example/public/.hidden/sample.json +0 -0
  10. package/example/public/images/sample.jpg +0 -0
  11. package/example/public/index.css +0 -0
  12. package/example/public/index.html +0 -0
  13. package/example/public/index.js +0 -0
  14. package/example/public2/test.css +0 -0
  15. package/example/public2/test.html +0 -0
  16. package/example/server-compress.js +0 -0
  17. package/example/server-dir-list.js +0 -0
  18. package/example/server-hidden-file.js +0 -0
  19. package/example/server.js +0 -0
  20. package/index.js +2 -1
  21. package/lib/dirList.js +1 -1
  22. package/package.json +1 -1
  23. package/test/content-type/binary +0 -0
  24. package/test/content-type/binary.br +0 -0
  25. package/test/content-type/index.css +0 -0
  26. package/test/content-type/index.css.br +0 -0
  27. package/test/content-type/index.html +0 -0
  28. package/test/content-type/index.html.br +0 -0
  29. package/test/content-type/sample.jpg +0 -0
  30. package/test/content-type/test.txt +0 -0
  31. package/test/content-type/test.txt.br +0 -0
  32. package/test/content-type.test.js +0 -0
  33. package/test/dir-list.test.js +8 -6
  34. package/test/static/.example +0 -0
  35. package/test/static/100%.txt +1 -0
  36. package/test/static/a .md +0 -0
  37. package/test/static/deep/path/for/test/index.html +0 -0
  38. package/test/static/deep/path/for/test/purpose/foo.html +0 -0
  39. package/test/static/foo.html +0 -0
  40. package/test/static/foobar.html +0 -0
  41. package/test/static/index.css +0 -0
  42. package/test/static/index.html +0 -0
  43. package/test/static/shallow/sample.jpg +0 -0
  44. package/test/static-dotfiles/.aaa +0 -0
  45. package/test/static-dotfiles/dir/index.html +0 -0
  46. package/test/static-dotfiles/test.txt +0 -0
  47. package/test/static-encode/[...]/a .md +0 -0
  48. package/test/static-hidden/.hidden/sample.json +0 -0
  49. package/test/static-pre-compressed/all-three.html +0 -0
  50. package/test/static-pre-compressed/all-three.html.br +0 -0
  51. package/test/static-pre-compressed/all-three.html.gz +0 -0
  52. package/test/static-pre-compressed/dir/index.html +0 -0
  53. package/test/static-pre-compressed/dir/index.html.br +0 -0
  54. package/test/static-pre-compressed/dir-gz/index.html +0 -0
  55. package/test/static-pre-compressed/dir-gz/index.html.gz +0 -0
  56. package/test/static-pre-compressed/empty/.gitkeep +0 -0
  57. package/test/static-pre-compressed/gzip-only.html +0 -0
  58. package/test/static-pre-compressed/gzip-only.html.gz +0 -0
  59. package/test/static-pre-compressed/index.html +0 -0
  60. package/test/static-pre-compressed/index.html.br +0 -0
  61. package/test/static-pre-compressed/sample.jpg +0 -0
  62. package/test/static-pre-compressed/sample.jpg.br +0 -0
  63. package/test/static-pre-compressed/uncompressed.html +0 -0
  64. package/test/static-symbolic-link/origin/subdir/subdir/index.html +0 -0
  65. package/test/static.test.js +27 -0
  66. package/test/static2/bar.html +0 -0
  67. package/test/static2/index.html +0 -0
  68. package/tsconfig.eslint.json +0 -0
  69. package/types/index.d.ts +0 -0
  70. package/types/index.test-d.ts +0 -0
package/.eslintrc.json CHANGED
File without changes
package/.gitattributes CHANGED
File without changes
File without changes
package/.github/stale.yml CHANGED
File without changes
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
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/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
- const stream = send(request.raw, pathnameForSend, options)
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastify/static",
3
- "version": "7.0.3",
3
+ "version": "7.0.4",
4
4
  "description": "Plugin for serving static files as fast as possible.",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
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
@@ -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/a .md" target="_blank">a .md</a></li>
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/a .md" target="_blank">a .md</a></li>
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({
File without changes
@@ -0,0 +1 @@
1
+ 100%
package/test/static/a .md 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
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -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
 
File without changes
File without changes
File without changes
package/types/index.d.ts CHANGED
File without changes
File without changes