Skip to content

Commit 70c7539

Browse files
committed
Add support for spaces in specification filenames
Performs a URLDecode of the pathname (e.g. "/acmeorg/foo/main/openapi%20with%20spaces.yml") to make sure we are able to find the file in GitHub.
1 parent eea56a3 commit 70c7539

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

__test__/projects/getProjectSelectionFromPath.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,69 @@ test("It moves specification ID to version ID if needed", () => {
288288
expect(sut.version!.id).toEqual("bar/baz")
289289
expect(sut.specification!.id).toEqual("hello")
290290
})
291+
292+
test("It supports specifications with spaces in their names", () => {
293+
const sut = getProjectSelectionFromPath({
294+
path: "/acme/foo/main/openapi with spaces.yml",
295+
projects: [
296+
{
297+
id: 'acme-foo',
298+
name: 'foo',
299+
displayName: "Ulrik's Playground",
300+
versions: [{
301+
id: 'main',
302+
name: 'main',
303+
specifications: [{
304+
id: "openapi with spaces.yml",
305+
name: "openapi with spaces.yml",
306+
url: "/api/blob/acme/foo-openapi/openapi with spaces.yml?ref=3dbafacbe57ac931ee750fc973bad3c81c9765bb",
307+
editURL: "https://github.com/acme/foo-openapi/edit/main/openapi with spaces.yml"
308+
}],
309+
url: 'https://github.com/acme/foo-openapi/tree/main',
310+
isDefault: true
311+
}],
312+
imageURL: '/api/blob/acme/foo-openapi/icon.png?ref=3dbafacbe57ac931ee750fc973bad3c81c9765bb',
313+
url: 'https://github.com/acme/foo-openapi',
314+
owner: 'acme',
315+
ownerUrl: 'https://github.com/acme'
316+
}
317+
]
318+
})
319+
expect(sut.project!.owner).toEqual("acme")
320+
expect(sut.project!.name).toEqual("foo")
321+
expect(sut.version!.id).toEqual("main")
322+
expect(sut.specification!.id).toEqual("openapi with spaces.yml")
323+
})
324+
325+
test("It supports specifications with URL-encoded spaces in their names", () => {
326+
const sut = getProjectSelectionFromPath({
327+
path: "/acme/foo/main/openapi%20with%20spaces.yml",
328+
projects: [
329+
{
330+
id: 'acme-foo',
331+
name: 'foo',
332+
displayName: "Ulrik's Playground",
333+
versions: [{
334+
id: 'main',
335+
name: 'main',
336+
specifications: [{
337+
id: "openapi with spaces.yml",
338+
name: "openapi with spaces.yml",
339+
url: "/api/blob/acme/foo-openapi/openapi with spaces.yml?ref=3dbafacbe57ac931ee750fc973bad3c81c9765bb",
340+
editURL: "https://github.com/acme/foo-openapi/edit/main/openapi with spaces.yml"
341+
}],
342+
url: 'https://github.com/acme/foo-openapi/tree/main',
343+
isDefault: true
344+
}],
345+
imageURL: '/api/blob/acme/foo-openapi/icon.png?ref=3dbafacbe57ac931ee750fc973bad3c81c9765bb',
346+
url: 'https://github.com/acme/foo-openapi',
347+
owner: 'acme',
348+
ownerUrl: 'https://github.com/acme'
349+
}
350+
]
351+
})
352+
expect(sut.project!.owner).toEqual("acme")
353+
expect(sut.project!.name).toEqual("foo")
354+
expect(sut.version!.id).toEqual("main")
355+
expect(sut.specification!.id).toEqual("openapi with spaces.yml")
356+
})

src/features/projects/domain/getProjectSelectionFromPath.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default function getProjectSelectionFromPath({
1616
if (path.startsWith("/")) {
1717
path = path.substring(1)
1818
}
19+
path = decodeURIComponent(path)
1920
const { owner: _owner, projectName: _projectName, versionId, specificationId } = guessSelection(path)
2021
// If no project is selected and the user only has a single project then we select that.
2122
let owner = _owner

0 commit comments

Comments
 (0)