Skip to content

Commit 074b31f

Browse files
committed
make it clear that the key parameter is encoded
1 parent ba09602 commit 074b31f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

packages/components/src/lib/filesystem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export class HyperparamFileSystem extends FileSystem {
148148
}
149149
getResolveUrl(source: string): string {
150150
const url = new URL('/api/store/get', this.endpoint)
151-
url.searchParams.append('key', encodeURIComponent(source))
151+
url.searchParams.append('key', source)
152152
return url.toString()
153153
}
154154
getSourceParts(source: string): SourcePart[] {
@@ -166,7 +166,7 @@ export class HyperparamFileSystem extends FileSystem {
166166
}
167167
async _fetchFilesList(prefix: string): Promise<HyperparamFileMetadata[]> {
168168
const url = new URL('/api/store/list', this.endpoint)
169-
url.searchParams.append('prefix', encodeURIComponent(prefix))
169+
url.searchParams.append('prefix', prefix)
170170
const res = await fetch(url)
171171
if (res.ok) {
172172
return await res.json() as HyperparamFileMetadata[]

packages/components/test/lib/filesystem.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it, test } from 'vitest'
1+
import { assert, describe, expect, it, test } from 'vitest'
22
import { HttpFileSystem, HyperparamFileSystem } from '../../src/lib/filesystem.js'
33

44
describe('HyperparamFileSystem', () => {
@@ -29,6 +29,18 @@ describe('HyperparamFileSystem', () => {
2929
})
3030
})
3131

32+
describe('HyperparamFileSystem.getResolveUrl', () => {
33+
test.for([
34+
'test.txt',
35+
'folder/subfolder/test.txt',
36+
])('encodes the parameters', (key: string) => {
37+
const endpoint = 'http://localhost:3000'
38+
const source = new HyperparamFileSystem({ endpoint }).getSource(key)
39+
assert(source?.kind === 'file')
40+
expect(source.resolveUrl).toBe(endpoint + '/api/store/get?key=' + encodeURIComponent(key))
41+
})
42+
})
43+
3244
describe('HttpFileSystem', () => {
3345
test.for([
3446
'http://example.com/test.txt',

0 commit comments

Comments
 (0)