Skip to content

Commit 488408b

Browse files
Arihant JainArihant Jain
authored andcommitted
Minor PR Comments, moved protocolRegex to constants file
1 parent d2bf7c9 commit 488408b

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

config/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports.PORTS = {
1010
MAX: 65535,
1111
MIN: 1
1212
};
13+
module.exports.PROTOCOL_REGEX = /(^\w+:|^)\/\//;
1314

1415
module.exports.LOGS = Object.freeze({
1516
NETWORK: 'NetworkStats.log',

src/commandLine.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ var CommandLineManager = {
119119
index = argv.indexOf('--proxy-host');
120120
if (index !== -1) {
121121
if (CommandLineManager.validArgValue(argv[index + 1])) {
122-
var hostRegex = /(^\w+:|^)\/\//;
123122
var host = argv[index + 1];
124-
if (host.match(hostRegex)) {
125-
host = host.replace(/(^\w+:|^)\/\//, '');
123+
if (host.match(constants.PROTOCOL_REGEX)) {
124+
host = host.replace(constants.PROTOCOL_REGEX, '');
126125
}
126+
console.log(host);
127127
RdGlobalConfig.proxy = RdGlobalConfig.proxy || {};
128128
RdGlobalConfig.proxy.host = host;
129129
argv.splice(index, 2);

test/commandLine.test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,25 @@ describe('CommandLineManager', function () {
3131

3232
it('parse proxy-host and proxy-port params', function () {
3333
sinon.stub(console, 'log');
34-
argv = argv.concat(['--proxy-host', 'http://host', '--proxy-port', '9687']);
34+
argv = argv.concat(['--proxy-host', 'host', '--proxy-port', '9687']);
3535
CommandLineManager.processArgs(argv);
3636
console.log.restore();
3737
expect(RdGlobalConfig.proxy.host).to.eql('host');
3838
expect(RdGlobalConfig.proxy.port).to.eql(9687);
3939
});
4040

41+
it('remove any protocal part from proxy-host', function () {
42+
sinon.stub(console, 'log');
43+
argv = argv.concat(['--proxy-host', 'http://host']);
44+
CommandLineManager.processArgs(argv);
45+
expect(RdGlobalConfig.proxy.host).to.eql('host');
46+
47+
argv = argv.concat(['--proxy-host', '//host']);
48+
CommandLineManager.processArgs(argv);
49+
console.log.restore();
50+
expect(RdGlobalConfig.proxy.host).to.eql('host');
51+
});
52+
4153
it('proxy-port is set to the default value when its not in the expected range', function () {
4254
sinon.stub(console, 'log');
4355
argv = argv.concat(['--proxy-host', 'host', '--proxy-port', '99999']);

0 commit comments

Comments
 (0)