Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion InfoLogger/public/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,13 @@ export default class Model extends Observable {
return;
} else if (params.q) {
this.getUserProfile();
this.log.filter.fromObject(JSON.parse(params.q.replaceAll('\n', '\\n')));
try {
this.log.filter.fromObject(JSON.parse(params.q.replaceAll('\n', '\\n')));
} catch (error) {
this.log.filter.resetCriteria();
this.updateRouteOnModelChange();
this.notification.show(`Invalid URL filter format: ${error.message}`, 'danger');
}
} else {
this.getUserProfile();
}
Expand Down
20 changes: 20 additions & 0 deletions InfoLogger/test/public/log-filter-actions-mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@ describe('Filter actions test-suite', async () => {
assert.strictEqual(searchParams, expectedParams);
});

it('should redirect to default filters and show JSON parse error on malformed q in URI', async () => {
const expectedDefaultParams = '?q={"severity":{"in":"I W E F"}}';

const locationAndNotification = await page.evaluate(() => {
const params = { q: '{"severity":{"in":"W I E F"' };
window.model.parseLocation(params);
return {
search: window.location.search,
notification: window.model.notification,
};
});

assert.strictEqual(decodeURI(locationAndNotification.search), expectedDefaultParams);
assert.strictEqual(locationAndNotification.notification.type, 'danger');
// CI/CD runs on Chromium so this assertion is based on Chromium's JSON engine's error message
assert.strictEqual(
locationAndNotification.notification.message,
'Invalid URL filter format: Expected \',\' or \'}\' after property value in JSON at position 27 (line 1 column 28)');
});

it('should update URI with new encoded "match" criteria', async () => {
/* eslint-disable max-len */
const decodedParams = '?q={"hostname":{"match":"\\"%ald_qdip01%"},"severity":{"in":"I W E F"}}';
Expand Down
Loading