<commit_before>var multiparty   = require('multiparty');
var tmp          = require('./../../config').tmpdir;
var router       = require('./../Router');
var ActionParser = require('./../ActionParser');
var AutoLoader   = require('./../../internal/autoLoader');
var async        = require('async');
var url          = require('url');

function UploadHandler() {
  return function(req, res, next) {
    async.waterfall([
      function(next){
        Router.resolve(next, url.parse(req.url).pathname);
      },

      function(route, next) {
        var action = route.controller
        var controller;
        var http_method = req.method === "DELETE" ? "DEL" : req.method;

        if (typeof action !== "string") {
          action = action[http_method];
        }

        action = ActionParser.parse(action);

        if (typeof action === "string") {
          action = {
            'classname': action,
            'method': false,
            'instance': false
          };
        }

        controller = autoLoader.invoke(action.classname);
        if (action.instance) { controller = new controller(); }
        if (action.method) { controller = controller[action.method]; }

        next(false, controller.upload);
      },

      function(accept, next) {
        var form  = new multiparty.Form({'uploadDir': tmp});
        var last = {
          'req': req,
          'res': res
        }

        if (accept) {
          form.parse(req, function(err, fields, files) {
            if (!err) {
              for (i in fields) {
                if (fields[i].length === 1) {
                  fields[i] = fields[i][0]
                }
              }
              last.req.body = fields;
              last.req.files = files;
            }

            next(err, last);
          });
        }
        else {<commit_msg>Fix a typo in Upload Handler that was crashing the server<commit_after>var multiparty   = require('multiparty');
var tmp          = require('./../../config').tmpdir;
var router       = require('./../Router');
var ActionParser = require('./../ActionParser');
var autoLoader   = require('./../../internal/autoLoader');
var async        = require('async');
var url          = require('url');

function UploadHandler() {
  return function(req, res, next) {
    async.waterfall([
      function(next){
        Router.resolve(next, url.parse(req.url).pathname);
      },

      function(route, next) {
        var action = route.controller
        var controller;
        var http_method = req.method === "DELETE" ? "DEL" : req.method;

        if (typeof action !== "string") {
          action = action[http_method];
        }

        action = ActionParser.parse(action);

        if (typeof action === "string") {
          action = {
            'classname': action,
            'method': false,
            'instance': false
          };
        }

        controller = autoLoader.invoke(action.classname);
        if (action.instance) { controller = new controller(); }
        if (action.method) { controller = controller[action.method]; }

        next(false, controller.upload);
      },

      function(accept, next) {
        var form  = new multiparty.Form({'uploadDir': tmp});
        var last = {
          'req': req,
          'res': res
        }

        if (accept) {
          form.parse(req, function(err, fields, files) {
            if (!err) {
              for (var i in fields) {
                if (fields[i].length === 1) {
                  fields[i] = fields[i][0]
                }
              }
              last.req.body = fields;
              last.req.files = files;
            }

            next(err, last);
          });
        }
        else {
{'fraction_non_alphanumeric': 0.1458557588805167, 'fraction_numerical': 0.001076426264800861, 'mean_word_length': 1.6361702127659574, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5613978', 'n_tokens_mistral': 1020, 'n_tokens_neox': 983, 'n_words': 237}