Skip to content

Commit

Permalink
Merge pull request #38 from nfischer/only-unix-var-reference
Browse files Browse the repository at this point in the history
Only use unix-style variable references
  • Loading branch information
dthree committed Feb 28, 2016
2 parents 12faf8e + 61f31a1 commit 8b2d45c
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 456 deletions.
44 changes: 7 additions & 37 deletions dist/preparser.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
'use strict';

var os = require('os');
var windows = os.platform() === 'win32';

// Replace out env variables.
var parseEnvVariables = function parseEnvVariables(input) {
var regex1 = windows ? /(\%.*?\%)/ : /(\${[^\$]*}|\$[^\$]*)/;
var regex2 = windows ? /^\%|\%$/g : /^\${|}$|^\$/g;

var total = '';
function iterate(str) {
var match = regex1.exec(str);
if (match !== null) {
var string = match[0];
var stripped = String(string.replace(regex2, '')).toLowerCase();
var value = null;
for (var name in process.env) {
if (process.env.hasOwnProperty(name)) {
if (String(name).toLowerCase() === stripped) {
value = process.env[name];
break;
} else if (!windows) {
value = ''; // default to empty string on Unix
}
}
}
var sliceLength = parseFloat(string.length) + parseFloat(match.index) - (value !== null ? 0 : 1);
var prefix = str.slice(0, sliceLength);
var suffix = str.slice(sliceLength, str.length);
if (value !== null) {
prefix = prefix.replace(string, value);
}
total += prefix;
return iterate(suffix);
}
return str;
}
var parseEnvVariables = function parseEnvVariables(input) {
var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g;

var out = iterate(input);
total += out;
return total;
return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) {
var varName = capture1 || capture2 || capture3;
// Return the value of the variable, or the empty string if not there
return process.env.hasOwnProperty(varName) ? process.env[varName] : '';
});
};

var preparser = function preparser(input) {
Expand Down
44 changes: 7 additions & 37 deletions packages/cat/dist/preparser.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
'use strict';

var os = require('os');
var windows = os.platform() === 'win32';

// Replace out env variables.
var parseEnvVariables = function parseEnvVariables(input) {
var regex1 = windows ? /(\%.*?\%)/ : /(\${[^\$]*}|\$[^\$]*)/;
var regex2 = windows ? /^\%|\%$/g : /^\${|}$|^\$/g;

var total = '';
function iterate(str) {
var match = regex1.exec(str);
if (match !== null) {
var string = match[0];
var stripped = String(string.replace(regex2, '')).toLowerCase();
var value = null;
for (var name in process.env) {
if (process.env.hasOwnProperty(name)) {
if (String(name).toLowerCase() === stripped) {
value = process.env[name];
break;
} else if (!windows) {
value = ''; // default to empty string on Unix
}
}
}
var sliceLength = parseFloat(string.length) + parseFloat(match.index) - (value !== null ? 0 : 1);
var prefix = str.slice(0, sliceLength);
var suffix = str.slice(sliceLength, str.length);
if (value !== null) {
prefix = prefix.replace(string, value);
}
total += prefix;
return iterate(suffix);
}
return str;
}
var parseEnvVariables = function parseEnvVariables(input) {
var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g;

var out = iterate(input);
total += out;
return total;
return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) {
var varName = capture1 || capture2 || capture3;
// Return the value of the variable, or the empty string if not there
return process.env.hasOwnProperty(varName) ? process.env[varName] : '';
});
};

var preparser = function preparser(input) {
Expand Down
44 changes: 7 additions & 37 deletions packages/cp/dist/preparser.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
'use strict';

var os = require('os');
var windows = os.platform() === 'win32';

// Replace out env variables.
var parseEnvVariables = function parseEnvVariables(input) {
var regex1 = windows ? /(\%.*?\%)/ : /(\${[^\$]*}|\$[^\$]*)/;
var regex2 = windows ? /^\%|\%$/g : /^\${|}$|^\$/g;

var total = '';
function iterate(str) {
var match = regex1.exec(str);
if (match !== null) {
var string = match[0];
var stripped = String(string.replace(regex2, '')).toLowerCase();
var value = null;
for (var name in process.env) {
if (process.env.hasOwnProperty(name)) {
if (String(name).toLowerCase() === stripped) {
value = process.env[name];
break;
} else if (!windows) {
value = ''; // default to empty string on Unix
}
}
}
var sliceLength = parseFloat(string.length) + parseFloat(match.index) - (value !== null ? 0 : 1);
var prefix = str.slice(0, sliceLength);
var suffix = str.slice(sliceLength, str.length);
if (value !== null) {
prefix = prefix.replace(string, value);
}
total += prefix;
return iterate(suffix);
}
return str;
}
var parseEnvVariables = function parseEnvVariables(input) {
var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g;

var out = iterate(input);
total += out;
return total;
return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) {
var varName = capture1 || capture2 || capture3;
// Return the value of the variable, or the empty string if not there
return process.env.hasOwnProperty(varName) ? process.env[varName] : '';
});
};

var preparser = function preparser(input) {
Expand Down
44 changes: 7 additions & 37 deletions packages/kill/dist/preparser.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
'use strict';

var os = require('os');
var windows = os.platform() === 'win32';

// Replace out env variables.
var parseEnvVariables = function parseEnvVariables(input) {
var regex1 = windows ? /(\%.*?\%)/ : /(\${[^\$]*}|\$[^\$]*)/;
var regex2 = windows ? /^\%|\%$/g : /^\${|}$|^\$/g;

var total = '';
function iterate(str) {
var match = regex1.exec(str);
if (match !== null) {
var string = match[0];
var stripped = String(string.replace(regex2, '')).toLowerCase();
var value = null;
for (var name in process.env) {
if (process.env.hasOwnProperty(name)) {
if (String(name).toLowerCase() === stripped) {
value = process.env[name];
break;
} else if (!windows) {
value = ''; // default to empty string on Unix
}
}
}
var sliceLength = parseFloat(string.length) + parseFloat(match.index) - (value !== null ? 0 : 1);
var prefix = str.slice(0, sliceLength);
var suffix = str.slice(sliceLength, str.length);
if (value !== null) {
prefix = prefix.replace(string, value);
}
total += prefix;
return iterate(suffix);
}
return str;
}
var parseEnvVariables = function parseEnvVariables(input) {
var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g;

var out = iterate(input);
total += out;
return total;
return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) {
var varName = capture1 || capture2 || capture3;
// Return the value of the variable, or the empty string if not there
return process.env.hasOwnProperty(varName) ? process.env[varName] : '';
});
};

var preparser = function preparser(input) {
Expand Down
44 changes: 7 additions & 37 deletions packages/ls/dist/preparser.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
'use strict';

var os = require('os');
var windows = os.platform() === 'win32';

// Replace out env variables.
var parseEnvVariables = function parseEnvVariables(input) {
var regex1 = windows ? /(\%.*?\%)/ : /(\${[^\$]*}|\$[^\$]*)/;
var regex2 = windows ? /^\%|\%$/g : /^\${|}$|^\$/g;

var total = '';
function iterate(str) {
var match = regex1.exec(str);
if (match !== null) {
var string = match[0];
var stripped = String(string.replace(regex2, '')).toLowerCase();
var value = null;
for (var name in process.env) {
if (process.env.hasOwnProperty(name)) {
if (String(name).toLowerCase() === stripped) {
value = process.env[name];
break;
} else if (!windows) {
value = ''; // default to empty string on Unix
}
}
}
var sliceLength = parseFloat(string.length) + parseFloat(match.index) - (value !== null ? 0 : 1);
var prefix = str.slice(0, sliceLength);
var suffix = str.slice(sliceLength, str.length);
if (value !== null) {
prefix = prefix.replace(string, value);
}
total += prefix;
return iterate(suffix);
}
return str;
}
var parseEnvVariables = function parseEnvVariables(input) {
var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g;

var out = iterate(input);
total += out;
return total;
return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) {
var varName = capture1 || capture2 || capture3;
// Return the value of the variable, or the empty string if not there
return process.env.hasOwnProperty(varName) ? process.env[varName] : '';
});
};

var preparser = function preparser(input) {
Expand Down
44 changes: 7 additions & 37 deletions packages/mkdir/dist/preparser.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
'use strict';

var os = require('os');
var windows = os.platform() === 'win32';

// Replace out env variables.
var parseEnvVariables = function parseEnvVariables(input) {
var regex1 = windows ? /(\%.*?\%)/ : /(\${[^\$]*}|\$[^\$]*)/;
var regex2 = windows ? /^\%|\%$/g : /^\${|}$|^\$/g;

var total = '';
function iterate(str) {
var match = regex1.exec(str);
if (match !== null) {
var string = match[0];
var stripped = String(string.replace(regex2, '')).toLowerCase();
var value = null;
for (var name in process.env) {
if (process.env.hasOwnProperty(name)) {
if (String(name).toLowerCase() === stripped) {
value = process.env[name];
break;
} else if (!windows) {
value = ''; // default to empty string on Unix
}
}
}
var sliceLength = parseFloat(string.length) + parseFloat(match.index) - (value !== null ? 0 : 1);
var prefix = str.slice(0, sliceLength);
var suffix = str.slice(sliceLength, str.length);
if (value !== null) {
prefix = prefix.replace(string, value);
}
total += prefix;
return iterate(suffix);
}
return str;
}
var parseEnvVariables = function parseEnvVariables(input) {
var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g;

var out = iterate(input);
total += out;
return total;
return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) {
var varName = capture1 || capture2 || capture3;
// Return the value of the variable, or the empty string if not there
return process.env.hasOwnProperty(varName) ? process.env[varName] : '';
});
};

var preparser = function preparser(input) {
Expand Down
44 changes: 7 additions & 37 deletions packages/mv/dist/preparser.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
'use strict';

var os = require('os');
var windows = os.platform() === 'win32';

// Replace out env variables.
var parseEnvVariables = function parseEnvVariables(input) {
var regex1 = windows ? /(\%.*?\%)/ : /(\${[^\$]*}|\$[^\$]*)/;
var regex2 = windows ? /^\%|\%$/g : /^\${|}$|^\$/g;

var total = '';
function iterate(str) {
var match = regex1.exec(str);
if (match !== null) {
var string = match[0];
var stripped = String(string.replace(regex2, '')).toLowerCase();
var value = null;
for (var name in process.env) {
if (process.env.hasOwnProperty(name)) {
if (String(name).toLowerCase() === stripped) {
value = process.env[name];
break;
} else if (!windows) {
value = ''; // default to empty string on Unix
}
}
}
var sliceLength = parseFloat(string.length) + parseFloat(match.index) - (value !== null ? 0 : 1);
var prefix = str.slice(0, sliceLength);
var suffix = str.slice(sliceLength, str.length);
if (value !== null) {
prefix = prefix.replace(string, value);
}
total += prefix;
return iterate(suffix);
}
return str;
}
var parseEnvVariables = function parseEnvVariables(input) {
var referenceRegex = /\${([a-zA-Z_][a-zA-Z0-9_]*)}|\$([a-zA-Z_][a-zA-Z0-9_]*)/g;

var out = iterate(input);
total += out;
return total;
return input.replace(referenceRegex, function (varRef, capture1, capture2, capture3) {
var varName = capture1 || capture2 || capture3;
// Return the value of the variable, or the empty string if not there
return process.env.hasOwnProperty(varName) ? process.env[varName] : '';
});
};

var preparser = function preparser(input) {
Expand Down

0 comments on commit 8b2d45c

Please sign in to comment.