mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-10 03:32:52 +00:00
committed by
Rainer Killinger
parent
ff9fb49deb
commit
9488451080
@@ -141,10 +141,13 @@ export class Elasticsearch implements Database {
|
||||
* @param uid The UID of the current bulk (for debugging purposes)
|
||||
*/
|
||||
static removeAliasChars(alias: string, uid: string | undefined): string {
|
||||
// spaces are included in some types, so throwing an error in this case would clutter up the log unnecessarily
|
||||
let formattedAlias = alias;
|
||||
while (formattedAlias.includes(' ')) {
|
||||
formattedAlias = formattedAlias.replace(' ', '');
|
||||
|
||||
// spaces are included in some types, replace them with underscores
|
||||
if (formattedAlias.includes(' ')) {
|
||||
formattedAlias = formattedAlias.trim();
|
||||
formattedAlias = formattedAlias.split(' ')
|
||||
.join('_');
|
||||
}
|
||||
// List of invalid characters: https://www.elastic.co/guide/en/elasticsearch/reference/6.6/indices-create-index.html
|
||||
['\\', '/', '*', '?', '"', '<', '>', '|', ',', '#'].forEach((value) => {
|
||||
|
||||
@@ -101,8 +101,16 @@ describe('Elasticsearch', function () {
|
||||
});
|
||||
|
||||
describe('removeAliasChars', function () {
|
||||
it('should remove spaces from both ends', function () {
|
||||
expect(Elasticsearch.removeAliasChars(' foobaralias ', 'bulk-uid')).to.be.equal('foobaralias');
|
||||
});
|
||||
|
||||
it('should replace inner spaces with underscores', function () {
|
||||
expect(Elasticsearch.removeAliasChars('foo bar alias', 'bulk-uid')).to.be.equal('foo_bar_alias');
|
||||
});
|
||||
|
||||
it('should remove invalid characters', function () {
|
||||
expect(Elasticsearch.removeAliasChars('f,o#o\\ b|ar/ <?al\ias>* ', 'bulk-uid')).to.be.equal('foobaralias');
|
||||
expect(Elasticsearch.removeAliasChars('f,o#o\\b|ar/<?al\ias>* ', 'bulk-uid')).to.be.equal('foobaralias');
|
||||
});
|
||||
|
||||
it('should remove invalid starting characters', function () {
|
||||
|
||||
Reference in New Issue
Block a user