fix: expand tilde file paths (#756)

Signed-off-by: Rui Chen <rui@chenrui.dev>
This commit is contained in:
Rui Chen
2026-03-15 00:09:15 -04:00
committed by GitHub
parent 45211baa90
commit 37f7a20824
5 changed files with 82 additions and 31 deletions

View File

@@ -1,6 +1,8 @@
import {
alignAssetName,
expandHomePattern,
isTag,
normalizeFilePattern,
normalizeGlobPattern,
normalizeTagName,
parseConfig,
@@ -541,6 +543,36 @@ describe('util', () => {
});
});
describe('expandHomePattern', () => {
it('expands a bare tilde to the provided home directory', () => {
assert.equal(expandHomePattern('~', '/home/runner'), '/home/runner');
});
it('expands posix-style tilde paths', () => {
assert.equal(expandHomePattern('~/release.txt', '/home/runner'), '/home/runner/release.txt');
});
it('leaves non-tilde paths unchanged', () => {
assert.equal(expandHomePattern('./release.txt', '/home/runner'), './release.txt');
});
});
describe('normalizeFilePattern', () => {
it('expands tilde paths before globbing', () => {
assert.equal(
normalizeFilePattern('~/release-assets/*.tgz', 'linux', '/home/runner'),
'/home/runner/release-assets/*.tgz',
);
});
it('expands tilde paths and normalizes windows separators', () => {
assert.equal(
normalizeFilePattern('~\\release-assets\\*.zip', 'win32', 'C:\\Users\\runner'),
'C:/Users/runner/release-assets/*.zip',
);
});
});
describe('replaceSpacesWithDots', () => {
it('replaces all spaces with dots', () => {
expect(alignAssetName('John Doe.bla')).toBe('John.Doe.bla');