Skip to content

Commit

Permalink
Merge pull request #406 from shapehq/fix/support-spaces-in-specificat…
Browse files Browse the repository at this point in the history
…ion-filenames

Add support for spaces in specification filenames
  • Loading branch information
ulrikandersen authored Oct 17, 2024
2 parents eea56a3 + 70c7539 commit 0386944
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
66 changes: 66 additions & 0 deletions __test__/projects/getProjectSelectionFromPath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,69 @@ test("It moves specification ID to version ID if needed", () => {
expect(sut.version!.id).toEqual("bar/baz")
expect(sut.specification!.id).toEqual("hello")
})

test("It supports specifications with spaces in their names", () => {
const sut = getProjectSelectionFromPath({
path: "/acme/foo/main/openapi with spaces.yml",
projects: [
{
id: 'acme-foo',
name: 'foo',
displayName: "Ulrik's Playground",
versions: [{
id: 'main',
name: 'main',
specifications: [{
id: "openapi with spaces.yml",
name: "openapi with spaces.yml",
url: "/api/blob/acme/foo-openapi/openapi with spaces.yml?ref=3dbafacbe57ac931ee750fc973bad3c81c9765bb",
editURL: "https://github.com/acme/foo-openapi/edit/main/openapi with spaces.yml"
}],
url: 'https://github.com/acme/foo-openapi/tree/main',
isDefault: true
}],
imageURL: '/api/blob/acme/foo-openapi/icon.png?ref=3dbafacbe57ac931ee750fc973bad3c81c9765bb',
url: 'https://github.com/acme/foo-openapi',
owner: 'acme',
ownerUrl: 'https://github.com/acme'
}
]
})
expect(sut.project!.owner).toEqual("acme")
expect(sut.project!.name).toEqual("foo")
expect(sut.version!.id).toEqual("main")
expect(sut.specification!.id).toEqual("openapi with spaces.yml")
})

test("It supports specifications with URL-encoded spaces in their names", () => {
const sut = getProjectSelectionFromPath({
path: "/acme/foo/main/openapi%20with%20spaces.yml",
projects: [
{
id: 'acme-foo',
name: 'foo',
displayName: "Ulrik's Playground",
versions: [{
id: 'main',
name: 'main',
specifications: [{
id: "openapi with spaces.yml",
name: "openapi with spaces.yml",
url: "/api/blob/acme/foo-openapi/openapi with spaces.yml?ref=3dbafacbe57ac931ee750fc973bad3c81c9765bb",
editURL: "https://github.com/acme/foo-openapi/edit/main/openapi with spaces.yml"
}],
url: 'https://github.com/acme/foo-openapi/tree/main',
isDefault: true
}],
imageURL: '/api/blob/acme/foo-openapi/icon.png?ref=3dbafacbe57ac931ee750fc973bad3c81c9765bb',
url: 'https://github.com/acme/foo-openapi',
owner: 'acme',
ownerUrl: 'https://github.com/acme'
}
]
})
expect(sut.project!.owner).toEqual("acme")
expect(sut.project!.name).toEqual("foo")
expect(sut.version!.id).toEqual("main")
expect(sut.specification!.id).toEqual("openapi with spaces.yml")
})
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function getProjectSelectionFromPath({
if (path.startsWith("/")) {
path = path.substring(1)
}
path = decodeURIComponent(path)
const { owner: _owner, projectName: _projectName, versionId, specificationId } = guessSelection(path)
// If no project is selected and the user only has a single project then we select that.
let owner = _owner
Expand Down

0 comments on commit 0386944

Please sign in to comment.