Skip to content

Commit

Permalink
[Observability onboarding] Applying regex globally (elastic#177719)
Browse files Browse the repository at this point in the history
Closes elastic#177704.

Co-authored-by: Marco Antonio Ghiani <[email protected]>
  • Loading branch information
yngrdyn and tonyghiani authored Mar 11, 2024
1 parent 111a627 commit d744b69
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { getFilename } from './get_filename';

describe('Observability onboarding - get_filename', () => {
it.each([
['test', '/logs-onboarding/test.log'],
['test', '/logs-onboarding/test.log'],
['test', 'test.log'],
['test', '/logs-onboarding/long-path/test.log'],
['test', '/logs-onboarding/test.20240223.log'],
['test', 'test'],
['', ''],
['test', '\\logs-onboarding\\test.log'],
['test', "/logs-on'boarding/test.log"],
['te_st', "/logs-on'boarding/te'st.log"],
['test_123', '/logs-onboarding/test 123.log'],
['t_e_s_t_1_2_3_', '/logs-onboarding/t-e%s*t#1@2!3$.log'],
])(
'should return "%s" for filename "%s"',
(expectedFilename: string, filePath: string) => {
expect(getFilename(filePath)).toBe(expectedFilename);
}
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ export const getFilename = (path?: string) => {
return '';
}

const filenameWithExt = path
.replace(/^.*[\\\/](?!\d*$)/, '')
.replace(/[\\\/]/, '');
const filenameWithExt = path.replace(/^.*[\\\/](?!\d*$)/g, '');
const filenameParts = filenameWithExt.split('.');

return replaceSpecialChars(filenameParts[0]);
Expand Down

0 comments on commit d744b69

Please sign in to comment.