Skip to content

Commit

Permalink
Fix: fix support for registry URLs without trailing slash (#4350)
Browse files Browse the repository at this point in the history
**Summary**

Fixes #4339. Also fixes handling of upper-case registry names.

**Test plan**

Added unit tests for `NpmRegistry.prototype.getRequestUrl()`.
  • Loading branch information
BYK authored and arcanis committed Sep 8, 2017
1 parent 6295408 commit d3f223c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
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

0 comments on commit d3f223c

Please sign in to comment.