mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
fix(Read/Write Files from Disk Node): Escape parenthesis when reading file (#11753)
This commit is contained in:
parent
9cc5bc1aef
commit
285534e6d0
|
@ -7,7 +7,7 @@ import type {
|
|||
} from 'n8n-workflow';
|
||||
|
||||
import glob from 'fast-glob';
|
||||
import { errorMapper } from '../helpers/utils';
|
||||
import { errorMapper, escapeSpecialCharacters } from '../helpers/utils';
|
||||
import { updateDisplayOptions } from '@utils/utilities';
|
||||
|
||||
export const properties: INodeProperties[] = [
|
||||
|
@ -82,6 +82,8 @@ export async function execute(this: IExecuteFunctions, items: INodeExecutionData
|
|||
try {
|
||||
fileSelector = String(this.getNodeParameter('fileSelector', itemIndex));
|
||||
|
||||
fileSelector = escapeSpecialCharacters(fileSelector);
|
||||
|
||||
if (/^[a-zA-Z]:/.test(fileSelector)) {
|
||||
fileSelector = fileSelector.replace(/\\\\/g, '/');
|
||||
}
|
||||
|
|
|
@ -30,3 +30,10 @@ export function errorMapper(
|
|||
|
||||
return new NodeOperationError(this.getNode(), error, { itemIndex, message, description });
|
||||
}
|
||||
|
||||
export function escapeSpecialCharacters(str: string) {
|
||||
// Escape parentheses
|
||||
str = str.replace(/[()]/g, '\\$&');
|
||||
|
||||
return str;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import { escapeSpecialCharacters } from '../helpers/utils';
|
||||
|
||||
describe('Read/Write Files from Disk, escapeSpecialCharacters', () => {
|
||||
it('should escape parentheses in a string', () => {
|
||||
const input = '/home/michael/Desktop/test(1).txt';
|
||||
const expectedOutput = '/home/michael/Desktop/test\\(1\\).txt';
|
||||
expect(escapeSpecialCharacters(input)).toBe(expectedOutput);
|
||||
});
|
||||
|
||||
it('should not modify strings that do not contain parentheses', () => {
|
||||
const input = '/home/michael/Desktop/test.txt';
|
||||
const expectedOutput = '/home/michael/Desktop/test.txt';
|
||||
expect(escapeSpecialCharacters(input)).toBe(expectedOutput);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue