You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/09/12 22:36:30 UTC
git commit: [CB-4797] Fix a crash on undefined platform in path.
Updated Branches:
refs/heads/master b1cadf0d1 -> de8f5477d
[CB-4797] Fix a crash on undefined platform in path.
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/de8f5477
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/de8f5477
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/de8f5477
Branch: refs/heads/master
Commit: de8f5477d4d62684f60818d793763e4623bfd324
Parents: b1cadf0
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Sep 12 16:36:06 2013 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Thu Sep 12 16:36:06 2013 -0400
----------------------------------------------------------------------
src/serve.js | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/de8f5477/src/serve.js
----------------------------------------------------------------------
diff --git a/src/serve.js b/src/serve.js
index a72bd23..54c7f64 100644
--- a/src/serve.js
+++ b/src/serve.js
@@ -30,15 +30,20 @@ var cordova_util = require('./util'),
function launchServer(projectRoot, port) {
var server = http.createServer(function(request, response) {
+ function do404() {
+ response.writeHead(404, {"Content-Type": "text/plain"});
+ response.write("404 Not Found\n");
+ response.end();
+ }
var urlPath = url.parse(request.url).pathname;
var firstSegment = /\/(.*?)\//.exec(urlPath);
if (!firstSegment) {
- response.writeHead(404, {"Content-Type": "text/plain"});
- response.write("404 Not Found\nPlease use URLs in the form /$platformId/www/...");
- response.end();
- return;
+ return do404();
}
var platformId = firstSegment[1];
+ if (!platforms[platformId]) {
+ return do404();
+ }
// Strip the platform out of the path.
urlPath = urlPath.slice(platformId.length + 1);
@@ -53,10 +58,7 @@ function launchServer(projectRoot, port) {
} else if (/^\/www\//.test(urlPath)) {
filePath = path.join(parser.www_dir(), urlPath.slice(5));
} else {
- response.writeHead(404, {"Content-Type": "text/plain"});
- response.write("404 Not Found\n");
- response.end();
- return;
+ return do404();
}
fs.exists(filePath, function(exists) {
@@ -84,9 +86,7 @@ function launchServer(projectRoot, port) {
readStream.pipe(response);
}
} else {
- response.writeHead(404, {"Content-Type": "text/plain"});
- response.write("404 Not Found\n");
- response.end();
+ return do404();
}
});