<commit_before>/**
 * @fileoverview Retrieve the configuration for the underlying app, reading
 * the configuration from config.defaults.json, config.json or process.env.
 *
 * The process.env declarations override those defined in config.json which,
 * in turn override those defined in config.defaults.json
 *
 * The JSON files may be invalid JSON files in the sense that they may contain
 * JavaScript comments, removed before parsing. They must be valid otherwise.
 *
 * Note: The config only checks process.env for configuration settings it finds
 * in config.json or config.defaults.json. In particular, you cannot define
 * new settings in process.env and expect them to be picked up by this helper.
 */
/*global __dirname, process, module*/

var fs = require('fs');
var path = require('path');

var config = {};
var filename = '';
var contents = '';

// Read config from config.defaults.json
try {
  filename = path.resolve(__dirname, '..', 'config.defaults.json');
  contents = fs.readFileSync(filename, 'utf8')
    .replace('\n', '')
    .replace(/\/\*[\s\S]*?\*\//g, '');
  config = JSON.parse(contents);
}
catch (e) {
}

// Read config from config.json
try {
  filename = path.resolve(__dirname, '..', 'config.json');
  contents = fs.readFileSync(filename, 'utf8')
    .replace('\n', '')
    .replace(/\/\*[\s\S]*?\*\//g, '');
  contents = JSON.parse(contents);
  Object.keys(contents).forEach(function (key) {
    config[key] = contents[key];
  });
}
catch (e) {
}

// Parse configuration keys and detect whether some environment setting
// is defined
Object.keys(config).forEach(function (key) {
  if (typeof process.env['DEPLOYMACHINE_' + key] !== 'undefined') {
    try {
      config[key] = JSON.parse(process.env['DEPLOYMACHINE_' + key]);
    }
    catch (e) {
      config[key] = process.env['DEPLOYMACHINE_' + key];
    }
  }
});

// Heroku passes the PORT env variable
if (typeof process.env.PORT !== 'undefined') {
  config.PORT = process.env.PORT;
}

module.exports = config;
<commit_msg>Newlines in environment variables were not expanded<commit_after>/**
 * @fileoverview Retrieve the configuration for the underlying app, reading
 * the configuration from config.defaults.json, config.json or process.env.
 *
 * The process.env declarations override those defined in config.json which,
 * in turn override those defined in config.defaults.json
 *
 * The JSON files may be invalid JSON files in the sense that they may contain
 * JavaScript comments, removed before parsing. They must be valid otherwise.
 *
 * Note: The config only checks process.env for configuration settings it finds
 * in config.json or config.defaults.json. In particular, you cannot define
 * new settings in process.env and expect them to be picked up by this helper.
 */
/*global __dirname, process, module*/

var fs = require('fs');
var path = require('path');

var config = {};
var filename = '';
var contents = '';

// Read config from config.defaults.json
try {
  filename = path.resolve(__dirname, '..', 'config.defaults.json');
  contents = fs.readFileSync(filename, 'utf8')
    .replace('\n', '')
    .replace(/\/\*[\s\S]*?\*\//g, '');
  config = JSON.parse(contents);
}
catch (e) {
}

// Read config from config.json
try {
  filename = path.resolve(__dirname, '..', 'config.json');
  contents = fs.readFileSync(filename, 'utf8')
    .replace('\n', '')
    .replace(/\/\*[\s\S]*?\*\//g, '');
  contents = JSON.parse(contents);
  Object.keys(contents).forEach(function (key) {
    config[key] = contents[key];
  });
}
catch (e) {
}

// Parse configuration keys and detect whether some environment setting
// is defined
Object.keys(config).forEach(function (key) {
  if (typeof process.env['DEPLOYMACHINE_' + key] !== 'undefined') {
    try {
      config[key] = JSON.parse(process.env['DEPLOYMACHINE_' + key]);
    }
    catch (e) {
      config[key] = process.env['DEPLOYMACHINE_' + key]
        .replace(/\\n/g, '\n');
    }
  }
});

// Heroku passes the PORT env variable
if (typeof process.env.PORT !== 'undefined') {
  config.PORT = process.env.PORT;
}

module.exports = config;

{'fraction_non_alphanumeric': 0.1532632608164263, 'fraction_numerical': 0.0009777560498655585, 'mean_word_length': 3.6029246344206975, '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': '1916525', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1232, 'n_words': 384}