-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1969 from rashidkpc/fix/query-validator-numbers
Fix query validation of numbers. Closes #1832
- Loading branch information
Showing
5 changed files
with
100 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
define(function (require) { | ||
var _ = require('lodash'); | ||
|
||
/** | ||
* Take text from the user and make it into a query object | ||
* @param {text} user's query input | ||
* @returns {object} | ||
*/ | ||
return function (text) { | ||
var matchAll = {query_string: {query: '*'}}; | ||
|
||
// If we get an empty object, treat it as a * | ||
if (_.isObject(text)) { | ||
if (Object.keys(text).length) { | ||
return text; | ||
} else { | ||
return matchAll; | ||
} | ||
} | ||
|
||
// Nope, not an object. | ||
text = (text || '').trim(); | ||
if (text.length === 0) return matchAll; | ||
|
||
if (text[0] === '{') { | ||
try { | ||
return JSON.parse(text); | ||
} catch (e) { | ||
return {query_string: {query: text}}; | ||
} | ||
} else { | ||
return {query_string: {query: text}}; | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
define(function (require) { | ||
var _ = require('lodash'); | ||
|
||
/** | ||
* Take text from the model and present it to the user as a string | ||
* @param {text} model value | ||
* @returns {string} | ||
*/ | ||
return function (text) { | ||
if (_.isString(text)) return text; | ||
if (_.isObject(text)) { | ||
if (text.query_string) return text.query_string.query; | ||
return JSON.stringify(text); | ||
} | ||
return text.toString(); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters