Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter in Explore view for script:xxx #1405

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions web/static/ivre/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ var GraphTopValues = (function(_super) {
this.filename = "TopValues";
}

function escapeRegex(string) {
return '\\"'+string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\\\$&').trim()+'\\"';
}
Comment on lines +97 to +99
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather remove the double quotes added here as they are not part of the regexp escape process:

Suggested change
function escapeRegex(string) {
return '\\"'+string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\\\$&').trim()+'\\"';
}
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The double quote is here to take the string in it's whole, and simplify the condition and make more readable, and also to prevent repeat the double quote everytime.
Maybe we should name it formatRegEx instead of escapeRegEx, and set a parameter to include the double quote or not ?
But you remove trim, and it's necessary to remove the line feed, if not the Javascript will fail and drop an error "unescaped line feed"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point for the .trim(). I think it is better to add it after the call, so I did it (see below)


$.extend(GraphTopValues.prototype, _super.prototype, {
get_url: function() {
return 'cgi/view/top/' + encodeURIComponent(this.field) + ':' +
Expand Down Expand Up @@ -268,6 +272,11 @@ var GraphTopValues = (function(_super) {
return 'setparam(FILTER, "script", "' + x + '");';
};
}
else if(field.substr(0, 7) === 'script:') {
preparefilter = function(x) {
return 'setparam(FILTER, "'+ field +'", "/' + escapeRegex(x) + '/");setparam(FILTER, "display:'+ field +'");';
Copy link
Member

@p-l- p-l- Jul 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should have the display: directive.

Suggested change
return 'setparam(FILTER, "'+ field +'", "/' + escapeRegex(x) + '/");setparam(FILTER, "display:'+ field +'");';
return 'setparam(FILTER, "'+ field +'", "/' + escapeRegExp(x).trim() + '/");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The display: is set to display the content we want to see while clicking.
When you click on the line, you have the list filtered, but without the details it's not really accurate.
Everytime I have to set the filter display:xxx to have details.
And it's more simple to click on the cross to deactivate filter than typing on the keyboard -> it's annoying ... :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand but that's not what exists in IVRE so far. For now, clicking in top values creates a filter for that value, it does not limit the display. For now, I'd rather keep it that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand but that's not what exists in IVRE so far. For now, clicking in top values creates a filter for that value, it does not limit the display. For now, I'd rather keep it that way.

No problem, you're the boss, boss ;)

};
}
else if(field === 'port') {
prepareoutput = function(x) {
return x.join(' / ');
Expand Down Expand Up @@ -1305,3 +1314,4 @@ var GraphDiffCategories = (function(_super) {

return GraphDiffCategories;
})(GraphIpPort);