Skip to content

Commit

Permalink
Prevent bad input for sort: and limit:
Browse files Browse the repository at this point in the history
  • Loading branch information
danny0838 committed Apr 10, 2023
1 parent ef587c6 commit e611886
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions webscrapbook/themes/default/templates/static_search.html
Expand Up @@ -494,7 +494,7 @@
error: [],
rules: {},
sorts: [],
limit: null,
limit: 0,
books: {
include: [],
exclude: [],
Expand Down Expand Up @@ -523,21 +523,27 @@
case "content":
query.sorts.push({key: "fulltext", subkey: key, order});
break;
default:
case "title": case "comment": case "file": case "source":
case "type": case "create": case "modify":
query.sorts.push({key: "meta", subkey: key, order});
break;
default:
addError("Invalid sort: " + key);
break;
}
};

const setLimit = (value, positive) => {
if (!positive) {
query.limit = null;
query.limit = 0;
return;
}

const newValue = parseInt(value);
if (!Number.isNaN(newValue)) {
const newValue = parseInt(value, 10);
if (Number.isInteger(newValue)) {
query.limit = newValue;
} else {
addError("Invalid limit: " + value);
}
};

Expand Down

0 comments on commit e611886

Please sign in to comment.