Skip to content

Commit

Permalink
Removing try / catch statements to expose underlying flaws & avoid …
Browse files Browse the repository at this point in the history
…deopts
  • Loading branch information
avoidwork committed Apr 5, 2018
1 parent 6a50c47 commit 61de547
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 30 deletions.
36 changes: 8 additions & 28 deletions lib/woodland.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,10 @@ class Woodland {
res.json = arg => {
let x = arg;

try {
if (typeof x === "string") {
x = regex.wrappedQuotes.test(x) ? x : JSON.stringify(x);
} else {
x = JSON.stringify(x);
}
} catch (e) {
void 0;
if (typeof x === "string") {
x = regex.wrappedQuotes.test(x) ? x : JSON.stringify(x);
} else {
x = JSON.stringify(x);
}

res.send(x, void 0, {"content-type": "application/json"});
Expand Down Expand Up @@ -184,11 +180,7 @@ class Woodland {
}

if (req.file === void 0 || empty) {
try {
res.respond(output);
} catch (e) {
void 0;
}
res.respond(output);

if (res.writable) {
res.end(empty === false ? body : void 0);
Expand Down Expand Up @@ -239,17 +231,9 @@ class Woodland {

if (iter.done === false) {
if (err !== void 0 && arity === 4) {
try {
iter.value(err, req, res, next);
} catch (e) {
next(e);
}
iter.value(err, req, res, next);
} else if (err === void 0 && arity <= 3) {
try {
iter.value(req, res, next);
} catch (e) {
next(e);
}
iter.value(req, res, next);
} else {
next(); // Error handler in the middle
}
Expand Down Expand Up @@ -384,11 +368,7 @@ class Woodland {
route = route.replace(/\/:(\w*)/g, "/(.*)");
}

try {
valid = new RegExp("^" + route + "$", "i").test(uri);
} catch (e) {
valid = new RegExp("^" + route.replace(/[-[\]\/{}()*+?.,\\^$|#]/g, "\\$&") + "$", "i").test(uri);
}
valid = new RegExp("^" + route.replace(/[-[\]\/{}()*+?.,\\^$|#]/g, "\\$&") + "$", "i").test(uri);

if (now === true && valid === false) {
params = false;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "woodland",
"version": "4.3.11",
"version": "5.0.0",
"description": "Lightweight HTTP/HTTPS/HTTP2 router with automatic `Allow` & `CORS` headers",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 61de547

Please sign in to comment.