Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

fix hostname filter #418

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions app/assets/javascripts/angular/filters/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ angular.module("Prometheus.filters").filter('hostnameFqdn', function() {

angular.module("Prometheus.filters").filter('hostname', function() {
return function(input) {
var a = document.createElement("a");
a.href = input;
return a.host.split(".", 1)[0];
var re = /^([^:\/?#]+:\/\/)?([^\/?#]*)?/;
var match = input.match(re);
return match ? match[2] : '';
};
});

Expand Down
20 changes: 16 additions & 4 deletions spec/javascripts/angular/filters/filters_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,20 @@ describe('filters', function() {
expect(host('http://sub-domain.domain.com/path?search')).toEqual('sub-domain.domain.com');
});

it('host', function() {
var host = $filter('hostname');
expect(host('http://domain.com/path?search')).toEqual('domain');
describe('host', function() {
it('with protocol', function() {
var host = $filter('hostname');
expect(host('http://domain.com:9090/path?search')).toEqual('domain.com:9090');
expect(host('http://domain.com/path?search')).toEqual('domain.com');
expect(host('ws://domain:9000/path?search')).toEqual('domain:9000');
});

it('without protocol', function() {
var host = $filter('hostname');
expect(host('domain.local:9090/path?search')).toEqual('domain.local:9090');
expect(host('domain.local/path?search')).toEqual('domain.local');
expect(host('domain:9000/path?search')).toEqual('domain:9000');
});
});

describe('regex', function() {
Expand All @@ -31,12 +42,13 @@ describe('filters', function() {
});

it('exact match', function() {
expect(regex('important-data.generic-data', '\.generic-data', '')).toEqual('important-data');
expect(regex('important-data.generic-data', '.generic-data', '')).toEqual('important-data');
});

it('special characters', function() {
expect(regex('important-data32398', '\\d', '')).toEqual('important-data');
expect(regex('important-data32398', '[a-zA-Z-]', '')).toEqual('32398');
expect(regex('some_random_stuff_SPECIAL', 'some_random_stuff_', '')).toEqual('SPECIAL');
});
});
});