mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[PLT-1444] Created latinise function and updated cleanUpUrlable function to utilize (#6273)
This commit is contained in:
committed by
Joram Wilander
parent
375cdbdb13
commit
4da45c0e76
23
webapp/tests/utils/latinise.test.jsx
Normal file
23
webapp/tests/utils/latinise.test.jsx
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
import {latinise} from 'utils/latinise.jsx';
|
||||
|
||||
describe('Latinise', () => {
|
||||
describe('handleNames', () => {
|
||||
test('should return ascii version of Dév Spé', () => {
|
||||
expect(latinise('Dév Spé')).
|
||||
toEqual('Dev Spe');
|
||||
});
|
||||
|
||||
test('should not replace any characters', () => {
|
||||
expect(latinise('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890')).
|
||||
toEqual('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890');
|
||||
});
|
||||
|
||||
test('should replace characters with diacritics with ascii equivalents', () => {
|
||||
expect(latinise('àáâãäåæçèéêëìíîïñòóôõöœùúûüýÿ')).
|
||||
toEqual('aaaaaaaeceeeeiiiinooooooeuuuuyy');
|
||||
});
|
||||
});
|
||||
});
|
||||
1003
webapp/utils/latinise.jsx
Normal file
1003
webapp/utils/latinise.jsx
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,11 @@
|
||||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
import {latinise} from 'utils/latinise.jsx';
|
||||
|
||||
export function cleanUpUrlable(input) {
|
||||
var cleaned = input.trim().replace(/-/g, ' ').replace(/[^\w\s]/gi, '').toLowerCase().replace(/\s/g, '-');
|
||||
var cleaned = latinise(input);
|
||||
cleaned = cleaned.trim().replace(/-/g, ' ').replace(/[^\w\s]/gi, '').toLowerCase().replace(/\s/g, '-');
|
||||
cleaned = cleaned.replace(/-{2,}/, '-');
|
||||
cleaned = cleaned.replace(/^-+/, '');
|
||||
cleaned = cleaned.replace(/-+$/, '');
|
||||
|
||||
Reference in New Issue
Block a user