Skip to content

Commit

Permalink
Capture picks a random value from an array, not just the first.
Browse files Browse the repository at this point in the history
  • Loading branch information
tatey committed Mar 17, 2016
1 parent 133704e commit 35dcd1c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/engine_http.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,12 @@ function dummyParser(body, callback) {

// doc is a JSON object
function extractJSONPath(doc, expr) {
let result = jsonpath.eval(doc, expr)[0];
return result;
let results = jsonpath.eval(doc, expr);
if (results.length > 1) {
return results[randomInt(0, results.length - 1)];
} else {
return results[0];
}
}

// doc is an libxmljs document object
Expand Down Expand Up @@ -367,3 +371,7 @@ function extractRegExp(doc, expr) {
function dummyExtractor() {
return '';
}

function randomInt (low, high) {
return Math.floor(Math.random() * (high - low + 1) + low);
}

0 comments on commit 35dcd1c

Please sign in to comment.