Skip to content

Commit

Permalink
fix(publisher-github): sanitizeName
Browse files Browse the repository at this point in the history
  • Loading branch information
mahnunchik committed Sep 22, 2023
1 parent 482db20 commit b77a32b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions packages/publisher/github/src/util/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,14 @@ export default class GitHub {
return github;
}

// Based on https://developer.github.com/v3/repos/releases/#upload-a-release-asset and
// Based on https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28#upload-a-release-asset and
// https://stackoverflow.com/questions/59081778/rules-for-special-characters-in-github-repository-name
static sanitizeName(name: string): string {
return path
.basename(name)
.replace(/\s/g, '.')
.replace(/\.+/g, '.')
.replace(/^\./g, '')
.replace(/\.$/g, '')
.replace(/[^\w.-]/g, '-');
.replace(/[^\w.-]+/g, '-');
}
}
4 changes: 2 additions & 2 deletions packages/publisher/github/test/github_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ describe('GitHub', () => {
});

it('should remove multiple periods in a row', () => {
expect(GitHub.sanitizeName('path/to/foo..bar')).to.equal('foobar');
expect(GitHub.sanitizeName('path/to/foo..bar')).to.equal('foo.bar');
});

it('should replace non-alphanumeric, non-hyphen characters with hyphens', () => {
expect(GitHub.sanitizeName('path/to/foo%bar baz.')).to.equal('foo-bar-baz');
expect(GitHub.sanitizeName('path/to/foo%$bar baz.')).to.equal('foo-bar-baz');
});
});
});

0 comments on commit b77a32b

Please sign in to comment.