Skip to content

Commit ee7eb82

Browse files
authored
test: Prevent regressions in static file serving of files outside the root (#2358)
1 parent d3142cf commit ee7eb82

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

packages/playground/assets/__tests__/assets.spec.ts

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const assetMatch = isBuild
1212
? /\/foo\/assets\/asset\.\w{8}\.png/
1313
: '/foo/nested/asset.png'
1414

15+
const outerAssetMatch = isBuild
16+
? /\/foo\/assets\/asset\.\w{8}\.png/
17+
: /\/foo\/@fs\/.+?\/css\/nested\/asset\.png/
18+
1519
const iconMatch = `/foo/icon.png`
1620

1721
test('should have no 404s', () => {
@@ -63,6 +67,12 @@ describe('asset imports from js', () => {
6367
expect(await page.textContent('.asset-import-absolute')).toMatch(assetMatch)
6468
})
6569

70+
test('outer', async () => {
71+
expect(await page.textContent('.asset-import-outer')).toMatch(
72+
outerAssetMatch
73+
)
74+
})
75+
6676
test('from /public', async () => {
6777
expect(await page.textContent('.public-import')).toMatch(iconMatch)
6878
})

packages/playground/assets/index.html

+14
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@ <h2>Raw References from publicDir</h2>
1414
Raw CSS from publicDir should load (this should be red)
1515
</li>
1616
<li>
17+
Filename with whitespace
1718
<img src="/white space.png" />
1819
</li>
20+
<li>
21+
Outer file using @fs
22+
<img class="asset-outer-img" alt="img" />
23+
</li>
1924
</ul>
2025

2126
<h2>Asset Imports from JS</h2>
2227
<ul>
2328
<li>Relative: <code class="asset-import-relative"></code></li>
2429
<li>Absolute: <code class="asset-import-absolute"></code></li>
30+
<li>Outer (@fs): <code class="asset-import-outer"></code></li>
2531
<li>From publicDir: <code class="public-import"></code></li>
2632
</ul>
2733

@@ -130,6 +136,10 @@ <h2>?url import</h2>
130136
import absoluteUrl from '/nested/asset.png'
131137
text('.asset-import-absolute', absoluteUrl)
132138

139+
import outerUrl from '@playground/css/nested/asset.png'
140+
text('.asset-import-outer', outerUrl)
141+
src('.asset-outer-img', outerUrl)
142+
133143
import publicUrl from '/icon.png'
134144
text('.public-import', publicUrl)
135145

@@ -146,4 +156,8 @@ <h2>?url import</h2>
146156
function text(el, text) {
147157
document.querySelector(el).textContent = text
148158
}
159+
160+
function src(el, src) {
161+
document.querySelector(el).src = src
162+
}
149163
</script>

packages/playground/assets/vite.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
publicDir: 'static',
99
resolve: {
1010
alias: {
11+
'@playground': path.resolve(__dirname, '..'),
1112
'@': path.resolve(__dirname, 'nested')
1213
}
1314
},
12.5 KB
Loading

0 commit comments

Comments
 (0)