Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: fix support for registry URLs without trailing slash #4350

Merged
merged 1 commit into from
Sep 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions __tests__/registries/npm-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,27 @@ describe('isScopedPackage functional test', () => {
});
});

describe('getRequestUrl functional test', () => {
test('returns pathname when it is a full URL', () => {
const testCwd = '.';
const {mockRequestManager, mockRegistries, mockReporter} = createMocks();
const npmRegistry = new NpmRegistry(testCwd, mockRegistries, mockRequestManager, mockReporter);
const fullURL = 'HTTP://xn--xample-hva.com:80/foo/bar/baz';

expect(npmRegistry.getRequestUrl('https://my.registry.co', fullURL)).toEqual(fullURL);
});

test('correctly handles registries lacking a trailing slash', () => {
const testCwd = '.';
const {mockRequestManager, mockRegistries, mockReporter} = createMocks();
const npmRegistry = new NpmRegistry(testCwd, mockRegistries, mockRequestManager, mockReporter);
const registry = 'https://my.registry.co/registry';
const pathname = 'foo/bar/baz';

expect(npmRegistry.getRequestUrl(registry, pathname)).toEqual('https://my.registry.co/registry/foo/bar/baz');
});
});

describe('getScope functional test', () => {
describe('matches scope correctly', () => {
const testCwd = '.';
Expand Down
4 changes: 2 additions & 2 deletions src/registries/npm-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ export default class NpmRegistry extends Registry {
}

getRequestUrl(registry: string, pathname: string): string {
const isUrl = /^https?:/.test(pathname);
const isUrl = /^https?:/i.test(pathname);

if (isUrl) {
return pathname;
} else {
return url.resolve(registry, pathname);
return url.resolve(addSuffix(registry, '/'), pathname);
}
}

Expand Down