willholley commented on a change in pull request #1137: Validate regex on
client side.
URL: https://github.com/apache/couchdb-fauxton/pull/1137#discussion_r224344633
##########
File path: app/addons/documents/mango/components/MangoQueryEditor.js
##########
@@ -130,16 +131,54 @@ export default class MangoQueryEditor extends Component {
notifyOnQueryError() {
if (this.editorHasErrors()) {
FauxtonAPI.addNotification({
- msg: 'Please fix the Javascript errors and try again.',
+ msg: 'Please fix the JSON errors and try again.',
type: 'error',
clear: true
});
return true;
}
+
return false;
}
+ getJsonIfValid(json) {
+ try {
+ return JSON.parse(json);
+ } catch (e) {
+ FauxtonAPI.addNotification({
+ msg: 'Please fix the JSON errors and try again. Error: ' + e.message,
+ type: 'error',
+ clear: true
+ });
+ }
+ }
+
+ isRegexValid(selector = {}) {
+ const regexes = Helper.getSelectorRegexes(selector);
+ const errors = _.reduce(regexes, (acc, val) => {
+ try {
+ new RegExp(val);
Review comment:
it's worth bearing in mind that Query uses [Regex
engine](http://erlang.org/doc/man/re.html) that is not perfectly compatible
with JavaScript's. This check will allow through regex strings that will not
work in Query and there may be regexes that are valid in Query but not valid JS
regexes.
Is there a particular use case that led to this PR? For instance, do we need
better server-side errors in the event that a bad regex is passed in a selector?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services