Skip to content

Fixed Usage of RegExp Objects #71

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
Binary file added Build/TermKit-x64.zip
Binary file not shown.
10 changes: 5 additions & 5 deletions HTML/client/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,19 @@ tc.shell.prototype = {

// Filter tokens.
for (i in command) if (i > limit) (function (token) {
if (/^\.\.?$/(token)) {
if (/^\.\.?$/.test(token)) {
// '.' and '..': pass
}
else if (/^-[A-Za-z0-9]$/(token)) {
else if (/^-[A-Za-z0-9]$/.test(token)) {
// Simple flag, no argument glued on: pass.
}
else if (m = /^(-[A-Za-z0-9])/(token)) {
else if (m = /^(-[A-Za-z0-9])/.exec(token)) {
// Multiple flags, or single flag with arg. Remove argument if key is p (password) or complex value.
if ((m[1][1] == 'p' || /[^A-Za-z0-9]/(m[1])) && m[1].length > 2) {
if ((m[1][1] == 'p' || /[^A-Za-z0-9]/.test(m[1])) && m[1].length > 2) {
command[i] = m[1] + wildcard;
}
}
else if (/^--[A-Za-z0-9_-]*$/(token)) {
else if (/^--[A-Za-z0-9_-]*$/.test(token)) {
// Long flag: pass
}
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* This is a CommonJS compatibility test. You can run this file with node.
*/
require.paths.unshift(__dirname + '/../scripts');
//require.paths.unshift(__dirname + '/../scripts');

var sys = require('sys'),
shSyntaxHighlighter = require('shCore').SyntaxHighlighter,
Expand Down
2 changes: 1 addition & 1 deletion HTML/syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function loadScript(url, callback) {
var h = SyntaxHighlighter.highlight;
SyntaxHighlighter.highlight = function (p, e) {
var m, that = this;
if (m = /brush: ([a-z]+)/(e.getAttribute('class'))) {
if (m = /brush: ([a-z]+)/.exec(e.getAttribute('class'))) {
if (urls[m[1]]) {
loadScript(urls[m[1]], function () {
h.call(that, p, e);
Expand Down
6 changes: 3 additions & 3 deletions HTML/tokenfield/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ tf.tokenPlain.triggerComplete = function (offset, event) {
test = this.contents;

// Split trailing space.
if (/ $/(test)) {
if (/ $/.test(test)) {
test = test.substring(0, test.length - 1);
out.push(new tf.tokenEmpty());
}

// Special characters must be quoted.
var type = /[ "'\\]/(test) ? tf.tokenQuoted : tf.tokenPlain;
var type = /[ "'\\]/.test(test) ? tf.tokenQuoted : tf.tokenPlain;
out.unshift(new type(test, this.style));

return out;
Expand Down Expand Up @@ -291,7 +291,7 @@ tf.tokenQuoted.triggerComplete = function (offset, event) {
test = this.contents;

// Split trailing space.
if (/ $/(test)) {
if (/ $/.test(test)) {
test = test.substring(0, test.length - 1);
out.push(new tf.tokenEmpty());
}
Expand Down
16 changes: 8 additions & 8 deletions Node/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exports.returnMeta = function (status, meta) {
code = number;
}
else if (typeof status == 'boolean') {
code = +status;
code = +status;
}
else {
status = false;
Expand Down Expand Up @@ -181,16 +181,16 @@ exports.parseArgs = function (tokens) {
i = 1, m;

for (; i < n; ++i) (function (token) {
if (m = /^-([A-Za-z0-9_])$/(tokens[i])) {
if (m = /^-([A-Za-z0-9_])$/.exec(tokens[i])) {
options[m[1]] = true;
}
else if (m = /^-([A-Za-z0-9_][A-Za-z0-9_-]*)$/(tokens[i])) {
else if (m = /^-([A-Za-z0-9_][A-Za-z0-9_-]*)$/.exec(tokens[i])) {
var flags = m[1].split(''), j;
for (j in flags) {
options[flags[j]] = true;
}
}
else if (m = /^--([A-Za-z0-9_-]+)$/(tokens[i])) {
else if (m = /^--([A-Za-z0-9_-]+)$/.exec(tokens[i])) {
if (typeof tokens[i + 1] != 'undefined' && tokens[i + 1][0] != '-') {
++i;
options[m[1]] = tokens[i];
Expand Down Expand Up @@ -226,13 +226,13 @@ exports.escapeBinary = function (data) {
var binary = data, n = binary.length, i = 0;

// Escape non-printables
binary = binary.replace(/([\u0000-\u001F\u0080-\u009F])/g, function (x, char) {
if (/[^\r\n\t]/(char)) {
var num = char.charCodeAt(0).toString(16);
binary = binary.replace(/([\u0000-\u001F\u0080-\u009F])/g, function (x, chr) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed variable name from char to chr, just to be on the sure side, since some sources say that Java keywords are reserved in JavaScript, although it seems to work in my local node.

if (/[^\r\n\t]/.exec(chr)) {
var num = chr.charCodeAt(0).toString(16);
while (num.length < 4) num = '0' + num;
return '\\u' + num;
}
return char;
return chr;
});

return binary;
Expand Down
2 changes: 1 addition & 1 deletion Node/nodekit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var termkit = {
version: 1,
};

require.paths.unshift(__dirname + '/../Shared/');
//require.paths.unshift(__dirname + '/../Shared/');

// Load requirements.
var http = require('http'),
Expand Down
2 changes: 1 addition & 1 deletion Node/shell/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ exports.autocomplete.prototype = {

// Trailing slashes.
function trail(path) {
if (!(/\/$/(path))) {
if (!(/\/$/.test(path))) {
path += '/';
}
return path;
Expand Down
16 changes: 8 additions & 8 deletions Node/shell/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ exports.plugins.text.prototype = extend(new exports.plugin(), {

exports.plugins.text.supports = function (headers) {
var type = headers.get('Content-Type');
return !!(/^text\//(type)) * 1;
return !!(/^text\//.exec(type)) * 1;
}

/**
Expand Down Expand Up @@ -168,7 +168,7 @@ exports.plugins.pdf.prototype = extend(new exports.plugin(), {

exports.plugins.pdf.supports = function (headers) {
var type = headers.get('Content-Type');
return !!(/^application\/pdf/(type)) * 2;
return !!(/^application\/pdf/.exec(type)) * 2;
}

/**
Expand Down Expand Up @@ -202,7 +202,7 @@ exports.plugins.html.prototype = extend(new exports.plugin(), {

exports.plugins.html.supports = function (headers) {
var type = headers.get('Content-Type');
return !!(/^text\/html/(type)) * 2;
return !!(/^text\/html/.exec(type)) * 2;
}

/**
Expand Down Expand Up @@ -286,7 +286,7 @@ exports.plugins.image.prototype = extend(new exports.plugin(), {

exports.plugins.image.supports = function (headers) {
var type = headers.get('Content-Type');
return !!(/^image\//(type)) * 1;
return !!(/^image\//.exec(type)) * 1;
};

/**
Expand Down Expand Up @@ -373,7 +373,7 @@ exports.plugins.files.prototype = extend(new exports.plugin(), {
exports.plugins.files.supports = function (headers) {
var type = headers.get('Content-Type'),
schema = headers.get('Content-Type', 'schema');
return !!(/^application\/json$/(type) && (schema == 'termkit.files')) * 3;
return !!(/^application\/json$/.exec(type) && (schema == 'termkit.files')) * 3;
};

/**
Expand Down Expand Up @@ -401,7 +401,7 @@ exports.plugins.unix.prototype = extend(new exports.plugin(), {
exports.plugins.unix.supports = function (headers) {
var type = headers.get('Content-Type'),
schema = headers.get('Content-Type', 'schema');
return !!(/^application\/octet-stream$/(type) && (schema == 'termkit.unix')) * 3;
return !!(/^application\/octet-stream$/.exec(type) && (schema == 'termkit.unix')) * 3;
}

/**
Expand All @@ -428,7 +428,7 @@ exports.plugins.binary.prototype = extend(new exports.plugin(), {

exports.plugins.binary.supports = function (headers) {
var type = headers.get('Content-Type');
return !!(/^application\/octet-stream/(type)) * 1;
return !!(/^application\/octet-stream/.exec(type)) * 1;
}

/**
Expand Down Expand Up @@ -481,6 +481,6 @@ exports.plugins.hex.prototype = extend(new exports.plugin(), {
exports.plugins.hex.supports = function (headers) {
var type = headers.get('Content-Type'),
schema = headers.get('Content-Type', 'schema');
return !!(/^application\/octet-stream$/(type) && (schema == 'termkit.hex')) * 3;
return !!(/^application\/octet-stream$/.exec(type) && (schema == 'termkit.hex')) * 3;
}

18 changes: 9 additions & 9 deletions Node/shell/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ function join(string) {

// Quote a string
function quote(string) {
if (/[\u0080-\uFFFF]/(string)) {
if (/[\u0080-\uFFFF]/.test(string)) {
// TODO: RFC2047 mime encoded tokens.
}
if (/[ ()<>@,;:\\"\[\]?=]/(string)) {
if (/[ ()<>@,;:\\"\[\]?=]/.test(string)) {
return '"' + string.replace(/([\\"])/g, '\\$1') + '"';
}
return string;
Expand Down Expand Up @@ -214,7 +214,7 @@ exports.headers.prototype = {
// Parse out fields (RFC 822).
var field;

while (field = /^([^:\x00-\x20]+): +(([^\r\n]|(?:\r\n[ \t]))+)(\r\n|$)/(headers)) {
while (field = /^([^:\x00-\x20]+): +(([^\r\n]|(?:\r\n[ \t]))+)(\r\n|$)/.exec(headers)) {

// Undo line folding.
var string = field[2].replace(/\r\n[ \t]/g, ''),
Expand Down Expand Up @@ -266,7 +266,7 @@ exports.headers.prototype = {
stack = stack.join('');

var match;
if (match = /([^=]+)=(.+)/(stack)) {
if (match = /([^=]+)=(.+)/.exec(stack)) {
params[match[1]] = match[2];
}
else if (stack.length) {
Expand Down Expand Up @@ -294,7 +294,7 @@ exports.headers.prototype = {
which = null,
match;
for (i in patterns) {
if (match = patterns[i](work)) {
if (match = patterns[i].exec(work)) {
which = i;
break;
}
Expand All @@ -315,7 +315,7 @@ exports.headers.prototype = {
// Balanced pairs found.
which = 'comment';
// Extract up to the i-th unescaped parenthesis.
token = new RegExp("([^\(\)]*[()]){" + (i + 1) + "}")(work)[0];
token = new RegExp("([^\(\)]*[()]){" + (i + 1) + "}").exec(work)[0];
break;
}
}
Expand Down Expand Up @@ -411,7 +411,7 @@ exports.headers.prototype = {
*/
param: function (key, value) {
// Parameter value (RFC 2231.. ugh)
if (/[\u0080-\uFFFF]/(value)) {
if (/[\u0080-\uFFFF]/.test(value)) {
var encoded = encodeURIComponent(value);
var safe = quote(value.replace(/[\u0080-\uFFFF]/g, ''));
return quote(key + '*') + '="' + encodeURIComponent(value) + '";' + quote(key) + '=' + quote(safe);
Expand Down Expand Up @@ -445,12 +445,12 @@ exports.sniff = function (file, data) {
}

// Detect binary data.
if (/[\u0000]/(attempt)) {
if (/[\u0000]/.test(attempt)) {
binary = true;
}

// Detect ansi color codes.
if (/[\u001b\[[0-9]+m/(attempt)) {
if (/[\u001b\[[0-9]+m/.test(attempt)) {
ansi = true;
if (type == 'application/octet-stream' || type == 'text/plain') {
type = [ 'application/octet-stream', { schema: 'termkit.unix' }];
Expand Down
4 changes: 2 additions & 2 deletions Node/shell/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,15 +438,15 @@ exports.filesReader.prototype = {
var type = 'application/octed-stream';

prefix = commonPrefix(types);
if (!(/^[^\/]+\/[^\/]+$/(prefix))) {
if (!(/^[^\/]+\/[^\/]+$/.test(prefix))) {
// If we only matched a type category (e.g. text/),
// coerce types to their base.
types = types.map(function (type) {
return meta.base(type);
});
prefix = commonPrefix(types);

if (!(/^[^\/]+\/[^\/]+$/(prefix))) {
if (!(/^[^\/]+\/[^\/]+$/.test(prefix))) {
// Replace with generic type.
type = meta.default(prefix) || 'application/octet-stream';
}
Expand Down
8 changes: 4 additions & 4 deletions Node/shell/worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require.paths.unshift('.');
require.paths.unshift('..');
require.paths.unshift(__dirname);
require.paths.unshift(__dirname + '/..');
//require.paths.unshift('.');
//require.paths.unshift('..');
//require.paths.unshift(__dirname);
//require.paths.unshift(__dirname + '/..');

var processor = require('processor');

Expand Down
12 changes: 6 additions & 6 deletions Node/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ var termkit = {
version: 1,
test: true,
};
require.paths.unshift('./socket.io-node/lib');
require.paths.unshift('.');
require.paths.unshift('shell');
require.paths.unshift('../Shared/');
//require.paths.unshift('./socket.io-node/lib');
//require.paths.unshift('.');
//require.paths.unshift('shell');
//require.paths.unshift('../Shared/');

var whenDone = require('misc').whenDone;
var EventEmitter = require("events").EventEmitter;
Expand Down Expand Up @@ -248,7 +248,7 @@ function testMeta(assert) {

// Generate headers back.
var string = headers.generate();
assert(/\r\n\r\n$/(string), 'Headers end in CRLF x2');
assert(/\r\n\r\n$/.exec(string), 'Headers end in CRLF x2');
assert(string.split(/\r\n/).length == 5 + 2, '5 Headers returned');
assert(/^Content-Type:\s*text\/plain;\s*charset=utf-16\r\n/m, 'Content-Type correct');
assert(/^Content-Disposition:\s*attachment;\s*filename=genome.jpeg;\s*modification-date="Wed, 12 February 1997 16:29:51 -0500"\r\n/m, 'Content-Disposition correct');
Expand Down Expand Up @@ -641,4 +641,4 @@ for (i in tests) (function (i, test) {
});
})(i, tests[i]);

(track(function () {}))();
(track(function () {}))();