Skip to content

Commit

Permalink
Got rid of safeFileName and replaced all uses with safeName.
Browse files Browse the repository at this point in the history
safeName is more restrictive than safeFileName, which is probably better to avoid getting weird names in weird places.

Part of #36.
  • Loading branch information
jkomoros committed Jul 4, 2023
1 parent e8cc0ec commit 15a9961
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
8 changes: 0 additions & 8 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ export const mockedResult = (input : string) : string => {
return 'Mocked result: ' + input;
};

//eslint-disable-next-line no-useless-escape
const ILLEGAL_FILE_CHARS = /[\/\?<>\\:\*\|"]/g;

//Returns a filename like input but with characters that are illegal on mac stripped out.
export const safeFileName = (input : string) : string => {
return input.replace(ILLEGAL_FILE_CHARS, '_');
};

const ILLEGAL_NAME_CHARS = /[^a-zA-Z0-9_-]/g;

export const safeName = (input : string) : string => {
Expand Down
4 changes: 2 additions & 2 deletions tools/associative_memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from './util.js';

import {
safeFileName
safeName
} from '../src/util.js';

import fs from 'fs';
Expand Down Expand Up @@ -50,7 +50,7 @@ export class AssociativeMemory {
}

get dir() : string {
return path.join(this._profile._profileDir, MEMORY_DIR, safeFileName(this._id), safeFileName(this._model));
return path.join(this._profile._profileDir, MEMORY_DIR, safeName(this._id), safeName(this._model));
}

get memoryFile() : string {
Expand Down
4 changes: 2 additions & 2 deletions tools/store_filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '../src/types.js';

import {
safeFileName
safeName
} from '../src/util.js';

import {
Expand Down Expand Up @@ -40,7 +40,7 @@ export class StoreFilesystem {
}

get file() : string {
return path.join(this.dir, safeFileName(this._id) + '.json');
return path.join(this.dir, safeName(this._id) + '.json');
}

_loadData() : Data {
Expand Down

0 comments on commit 15a9961

Please sign in to comment.