Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
protecting inputs from airtable
Browse files Browse the repository at this point in the history
  • Loading branch information
bdavidxyz committed Dec 8, 2016
1 parent 383c195 commit d3d3b23
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions api/lib/domain/services/solution-service-qrocm-dep.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ const utils = require('./solution-service-utils');
const yaml = require('js-yaml');
const _ = require('lodash');

// We expect that parsing from airtable returns an Object
// whose all values are array, like this :
// { Google: [ 'Google', 'google.fr', 'Google Search' ], Yahoo: [ 'Yahoo', 'Yahoo Answer' ] }
function _isValidSolution(solution) {
let result = false;
if (_.isObject(solution)) {
result = _.every(solution, function(item) {
return _.isArray(item) && _.every(item, (e) => _.isString(e));
});
}
return result;
}

module.exports = {

match (yamlAnswer, yamlSolution) {
Expand All @@ -16,6 +29,10 @@ module.exports = {
// solution is
// { Google: [ 'Google', 'google.fr', 'Google Search' ], Yahoo: [ 'Yahoo', 'Yahoo Answer' ] }

if (!_isValidSolution(solution)) {
return result;
}

const possibleAnswers = {};
_.each(solution, (answerList, solutionKey) => {
_.each(answerList, (answer) => {
Expand Down

0 comments on commit d3d3b23

Please sign in to comment.