mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
fix(Read/Write Files from Disk Node): Escape parenthesis when reading file (#11753)
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user