Commit e03967d3 authored by Nicholas Kindrachuk (njk361)'s avatar Nicholas Kindrachuk (njk361)
Browse files

Merge branch 'dev' into 'master'

Dev

See merge request !5
parents 806d93c8 f91caaa9
# CMPT370-Fantastic 4
Intermediate Software Engineering
Link to the Wiki page https://git.cs.usask.ca/yol474/cmpt370-fantastic-4/wikis
<hr>
## Getting Started
How to run:
Instructions to get the web application running on a local machine.
Use **git clone https://git.cs.usask.ca/yol474/cmpt370-fantastic-4.git** in the command line
### Prerequisites
Requires **nodeJs** to run.<br>
What must be installed to run the software:
Run the following commands inside the **air370proj folder** containing the
app.js file, the database, and the views folder.<br>
```
nodejs, sqlite3, express, ejs, nodemailer
```
**npm init <br>
npm install sqlite3<br>
npm install express<br>
npm install ejs<br>**
### Installing
How to run the application:
Finally, run **'node app.js'** in the terminal to start the server. <br>
The localhost will be listening at: http://localhost:2020/
Clone the git branch
**Current Restrictions**
```
git clone https://git.cs.usask.ca/yol474/cmpt370-fantastic-4.git
```
Only direct flights can be used currently the other options will refresh page.<br>
Examples of available flights for testing:
* Calgary to London
* Saskatoon to Calgary
* Calgary to Paris
Download and install nodejs
```
https://nodejs.org/en/download/
```
Navigate to the **air370proj** folder that contains **app.js**
```
cmpt370-fantastic-4\air370proj\AirPararies370proj\air370proj
```
Use npm to install the following requirements
```
npm init
npm i sqlite3
npm i express
npm i ejs
npm i nodemailer
```
Run app.js using command line
```
node app.js
```
Application will be live on port 2020
```
localhost:2020/
```
If you would like a reference when booking a flight be sure to use a real email in the form.<br>
The site may need to be reactivated to have the latest booking information since
it is local.
### Wiki
Features details for all milestones and group members<br>
https://git.cs.usask.ca/yol474/cmpt370-fantastic-4/wikis
......@@ -22,7 +22,7 @@
"_resolved": "https://registry.npmjs.org/ejs/-/ejs-3.0.1.tgz",
"_shasum": "30c8f6ee9948502cc32e85c37a3f8b39b5a614a5",
"_spec": "ejs@^3.0.1",
"_where": "C:\\Users\\nkind\\OneDrive\\Documents\\cmpt370-fantastic-4\\air370proj\\AirPararies370proj\\air370proj",
"_where": "C:\\Users\\nkind\\Desktop\\cmpt370-fantastic-4\\air370proj\\AirPararies370proj\\air370proj",
"author": {
"name": "Matthew Eernisse",
"email": "mde@fleegix.org",
......
......@@ -22,7 +22,7 @@
"_resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz",
"_shasum": "4491fc38605cf51f8629d39c2b5d026f98a4c134",
"_spec": "express@^4.17.1",
"_where": "C:\\Users\\nkind\\OneDrive\\Documents\\cmpt370-fantastic-4\\air370proj\\AirPararies370proj\\air370proj",
"_where": "C:\\Users\\nkind\\Desktop\\cmpt370-fantastic-4\\air370proj\\AirPararies370proj\\air370proj",
"author": {
"name": "TJ Holowaychuk",
"email": "tj@vision-media.ca"
......
......@@ -2,3 +2,7 @@ language: node_js
node_js:
- "0.8"
- "0.10"
- "0.12"
- "iojs"
before_install:
- npm install -g npm@~1.4.6
var argv = require('../')(process.argv.slice(2));
console.dir(argv);
console.log(argv);
module.exports = function (args, opts) {
if (!opts) opts = {};
var flags = { bools : {}, strings : {} };
[].concat(opts['boolean']).filter(Boolean).forEach(function (key) {
flags.bools[key] = true;
});
[].concat(opts.string).filter(Boolean).forEach(function (key) {
flags.strings[key] = true;
});
var flags = { bools : {}, strings : {}, unknownFn: null };
if (typeof opts['unknown'] === 'function') {
flags.unknownFn = opts['unknown'];
}
if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {
flags.allBools = true;
} else {
[].concat(opts['boolean']).filter(Boolean).forEach(function (key) {
flags.bools[key] = true;
});
}
var aliases = {};
Object.keys(opts.alias || {}).forEach(function (key) {
......@@ -20,7 +24,14 @@ module.exports = function (args, opts) {
}));
});
});
[].concat(opts.string).filter(Boolean).forEach(function (key) {
flags.strings[key] = true;
if (aliases[key]) {
flags.strings[aliases[key]] = true;
}
});
var defaults = opts['default'] || {};
var argv = { _ : [] };
......@@ -35,7 +46,16 @@ module.exports = function (args, opts) {
args = args.slice(0, args.indexOf('--'));
}
function setArg (key, val) {
function argDefined(key, arg) {
return (flags.allBools && /^--[^=]+$/.test(arg)) ||
flags.strings[key] || flags.bools[key] || aliases[key];
}
function setArg (key, val, arg) {
if (arg && flags.unknownFn && !argDefined(key, arg)) {
if (flags.unknownFn(arg) === false) return;
}
var value = !flags.strings[key] && isNumber(val)
? Number(val) : val
;
......@@ -45,7 +65,41 @@ module.exports = function (args, opts) {
setKey(argv, x.split('.'), value);
});
}
function setKey (obj, keys, value) {
var o = obj;
for (var i = 0; i < keys.length-1; i++) {
var key = keys[i];
if (key === '__proto__') return;
if (o[key] === undefined) o[key] = {};
if (o[key] === Object.prototype || o[key] === Number.prototype
|| o[key] === String.prototype) o[key] = {};
if (o[key] === Array.prototype) o[key] = [];
o = o[key];
}
var key = keys[keys.length - 1];
if (key === '__proto__') return;
if (o === Object.prototype || o === Number.prototype
|| o === String.prototype) o = {};
if (o === Array.prototype) o = [];
if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {
o[key] = value;
}
else if (Array.isArray(o[key])) {
o[key].push(value);
}
else {
o[key] = [ o[key], value ];
}
}
function aliasIsBoolean(key) {
return aliases[key].some(function (x) {
return flags.bools[x];
});
}
for (var i = 0; i < args.length; i++) {
var arg = args[i];
......@@ -54,27 +108,33 @@ module.exports = function (args, opts) {
// 'dotall' regex modifier. See:
// http://stackoverflow.com/a/1068308/13216
var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
setArg(m[1], m[2]);
var key = m[1];
var value = m[2];
if (flags.bools[key]) {
value = value !== 'false';
}
setArg(key, value, arg);
}
else if (/^--no-.+/.test(arg)) {
var key = arg.match(/^--no-(.+)/)[1];
setArg(key, false);
setArg(key, false, arg);
}
else if (/^--.+/.test(arg)) {
var key = arg.match(/^--(.+)/)[1];
var next = args[i + 1];
if (next !== undefined && !/^-/.test(next)
&& !flags.bools[key]
&& (aliases[key] ? !flags.bools[aliases[key]] : true)) {
setArg(key, next);
&& !flags.allBools
&& (aliases[key] ? !aliasIsBoolean(key) : true)) {
setArg(key, next, arg);
i++;
}
else if (/^(true|false)$/.test(next)) {
setArg(key, next === 'true');
setArg(key, next === 'true', arg);
i++;
}
else {
setArg(key, flags.strings[key] ? '' : true);
setArg(key, flags.strings[key] ? '' : true, arg);
}
}
else if (/^-[^-]+/.test(arg)) {
......@@ -85,24 +145,30 @@ module.exports = function (args, opts) {
var next = arg.slice(j+2);
if (next === '-') {
setArg(letters[j], next)
setArg(letters[j], next, arg)
continue;
}
if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {
setArg(letters[j], next.split('=')[1], arg);
broken = true;
break;
}
if (/[A-Za-z]/.test(letters[j])
&& /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
setArg(letters[j], next);
setArg(letters[j], next, arg);
broken = true;
break;
}
if (letters[j+1] && letters[j+1].match(/\W/)) {
setArg(letters[j], arg.slice(j+2));
setArg(letters[j], arg.slice(j+2), arg);
broken = true;
break;
}
else {
setArg(letters[j], flags.strings[letters[j]] ? '' : true);
setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);
}
}
......@@ -110,23 +176,29 @@ module.exports = function (args, opts) {
if (!broken && key !== '-') {
if (args[i+1] && !/^(-|--)[^-]/.test(args[i+1])
&& !flags.bools[key]
&& (aliases[key] ? !flags.bools[aliases[key]] : true)) {
setArg(key, args[i+1]);
&& (aliases[key] ? !aliasIsBoolean(key) : true)) {
setArg(key, args[i+1], arg);
i++;
}
else if (args[i+1] && /true|false/.test(args[i+1])) {
setArg(key, args[i+1] === 'true');
else if (args[i+1] && /^(true|false)$/.test(args[i+1])) {
setArg(key, args[i+1] === 'true', arg);
i++;
}
else {
setArg(key, flags.strings[key] ? '' : true);
setArg(key, flags.strings[key] ? '' : true, arg);
}
}
}
else {
argv._.push(
flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)
);
if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
argv._.push(
flags.strings['_'] || !isNumber(arg) ? arg : Number(arg)
);
}
if (opts.stopEarly) {
argv._.push.apply(argv._, args.slice(i + 1));
break;
}
}
}
......@@ -140,9 +212,17 @@ module.exports = function (args, opts) {
}
});
notFlags.forEach(function(key) {
argv._.push(key);
});
if (opts['--']) {
argv['--'] = new Array();
notFlags.forEach(function(key) {
argv['--'].push(key);
});
}
else {
notFlags.forEach(function(key) {
argv._.push(key);
});
}
return argv;
};
......@@ -157,31 +237,9 @@ function hasKey (obj, keys) {
return key in o;
}
function setKey (obj, keys, value) {
var o = obj;
keys.slice(0,-1).forEach(function (key) {
if (o[key] === undefined) o[key] = {};
o = o[key];
});
var key = keys[keys.length - 1];
if (o[key] === undefined || typeof o[key] === 'boolean') {
o[key] = value;
}
else if (Array.isArray(o[key])) {
o[key].push(value);
}
else {
o[key] = [ o[key], value ];
}
}
function isNumber (x) {
if (typeof x === 'number') return true;
if (/^0x[0-9a-f]+$/i.test(x)) return true;
return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
}
function longest (xs) {
return Math.max.apply(null, xs.map(function (x) { return x.length }));
}
{
"_from": "minimist@0.0.8",
"_id": "minimist@0.0.8",
"_from": "minimist@^1.2.5",
"_id": "minimist@1.2.5",
"_inBundle": false,
"_integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
"_integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
"_location": "/minimist",
"_phantomChildren": {},
"_requested": {
"type": "version",
"type": "range",
"registry": true,
"raw": "minimist@0.0.8",
"raw": "minimist@^1.2.5",
"name": "minimist",
"escapedName": "minimist",
"rawSpec": "0.0.8",
"rawSpec": "^1.2.5",
"saveSpec": null,
"fetchSpec": "0.0.8"
"fetchSpec": "^1.2.5"
},
"_requiredBy": [
"/mkdirp"
"/mkdirp",
"/rc"
],
"_resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"_shasum": "857fcabfc3397d2625b8228262e86aa7a011b05d",
"_spec": "minimist@0.0.8",
"_where": "C:\\Users\\nkind\\desktop\\cmpt370-fantastic-4\\air370proj\\AirPararies370proj\\air370proj\\node_modules\\mkdirp",
"_resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"_shasum": "67d66014b66a6a8aaa0c083c5fd58df4e4e97602",
"_spec": "minimist@^1.2.5",
"_where": "C:\\Users\\nkind\\Desktop\\cmpt370-fantastic-4\\air370proj\\AirPararies370proj\\air370proj\\node_modules\\mkdirp",
"author": {
"name": "James Halliday",
"email": "mail@substack.net",
......@@ -34,8 +35,9 @@
"deprecated": false,
"description": "parse argument options",
"devDependencies": {
"covert": "^1.0.0",
"tap": "~0.4.0",
"tape": "~1.0.4"
"tape": "^3.5.0"
},
"homepage": "https://github.com/substack/minimist",
"keywords": [
......@@ -52,6 +54,7 @@
"url": "git://github.com/substack/minimist.git"
},
"scripts": {
"coverage": "covert test/*.js",
"test": "tap test/*.js"
},
"testling": {
......@@ -67,5 +70,5 @@
"opera/12"
]
},
"version": "0.0.8"
"version": "1.2.5"
}
......@@ -5,15 +5,11 @@ parse argument options
This module is the guts of optimist's argument parser without all the
fanciful decoration.
[![browser support](https://ci.testling.com/substack/minimist.png)](http://ci.testling.com/substack/minimist)
[![build status](https://secure.travis-ci.org/substack/minimist.png)](http://travis-ci.org/substack/minimist)
# example
``` js
var argv = require('minimist')(process.argv.slice(2));
console.dir(argv);
console.log(argv);
```
```
......@@ -33,6 +29,13 @@ $ node example/parse.js -x 3 -y 4 -n5 -abc --beep=boop foo bar baz
beep: 'boop' }
```
# security
Previous versions had a prototype pollution bug that could cause privilege
escalation in some circumstances when handling untrusted user input.
Please use version 1.2.3 or later: https://snyk.io/vuln/SNYK-JS-MINIMIST-559764
# methods
``` js
......@@ -55,10 +58,29 @@ options can be:
* `opts.string` - a string or array of strings argument names to always treat as
strings
* `opts.boolean` - a string or array of strings to always treat as booleans
* `opts.boolean` - a boolean, string or array of strings to always treat as
booleans. if `true` will treat all double hyphenated arguments without equal signs
as boolean (e.g. affects `--foo`, not `-f` or `--foo=bar`)
* `opts.alias` - an object mapping string names to strings or arrays of string
argument names to use as aliases
* `opts.default` - an object mapping string argument names to default values
* `opts.stopEarly` - when true, populate `argv._` with everything after the
first non-option
* `opts['--']` - when true, populate `argv._` with everything before the `--`
and `argv['--']` with everything after the `--`. Here's an example:
```
> require('./')('one two three -- four five --six'.split(' '), { '--': true })
{ _: [ 'one', 'two', 'three' ],
'--': [ 'four', 'five', '--six' ] }
```
Note that with `opts['--']` set, parsing for arguments still stops after the
`--`.
* `opts.unknown` - a function which is invoked with a command line parameter not
defined in the `opts` configuration object. If the function returns `false`, the
unknown option is not added to `argv`.
# install
......
......@@ -22,3 +22,10 @@ test('-a -- b', function (t) {
t.deepEqual(parse([ '--a', '--', 'b' ]), { a: true, _: [ 'b' ] });
t.deepEqual(parse([ '--a', '--', 'b' ]), { a: true, _: [ 'b' ] });
});
test('move arguments after the -- into their own `--` array', function(t) {
t.plan(1);
t.deepEqual(
parse([ '--name', 'John', 'before', '--', 'after' ], { '--': true }),
{ name: 'John', _: [ 'before' ], '--': [ 'after' ] });
});
......@@ -18,3 +18,18 @@ test('boolean default false', function (t) {
t.equal(argv.somefalse, false);
t.end();
});
test('boolean default to null', function (t) {
var argv = parse([], {
boolean: 'maybe',
default: { maybe: null }
});
t.equal(argv.maybe, null);
var argv = parse(['--maybe'], {
boolean: 'maybe',
default: { maybe: null }
});
t.equal(argv.maybe, true);
t.end();
})
......@@ -14,3 +14,9 @@ test('dotted default', function (t) {
t.equal(argv.aa.bb, 11);
t.end();
});
test('dotted default with no alias', function (t) {
var argv = parse('', {default: {'a.b': 11}});
t.equal(argv.a.b, 11);
t.end();
});
......@@ -42,32 +42,6 @@ test('comprehensive', function (t) {
t.end();
});
test('nums', function (t) {
var argv = parse([
'-x', '1234',
'-y', '5.67',
'-z', '1e7',
'-w', '10f',