n8n icon indicating copy to clipboard operation
n8n copied to clipboard

.replaceAll doing weird stuff

Open Nahiiko opened this issue 1 year ago • 2 comments

Bug Description

When using replaceAll function inside Convert to File node (XLS,File Name param) I saw weird behavior. Indeed, the following: '{{ $json.Projects.replaceAll("y","") }}.xlsxyy' works perfectly fine, only the "y" in $json.Projects is replaced. example: '{{helloyworld}}.xlsxy' -> 'hello_world.xlsxy' But '{{ $json.Projects.replaceAll(" ","") }}.xlsx ' Looks fine when looking at the file output, but when clicking download you get an underscore OUTSIDE the js code: '{{hello world}}.xls '-> hello_world.xlsx_

To Reproduce

Screenshot 2024-02-15 at 11 10 38

Expected behavior

Looks fine here, but click download and you get 'he_llo.xlsx_' instead of 'he_llo.xlsx'

Operating System

Synology DSM 7.1

n8n Version

n8nio/n8n:latest

Node.js Version

v18.19.0

Database

PostgreSQL

Execution mode

main (default)

Nahiiko avatar Feb 15 '24 10:02 Nahiiko

Hey @Nahiiko

In the example you provided do you actually have an extra space at the end of the file extension or is that just a typo?

What is the actual value of json.Projects?

Joffcom avatar Feb 16 '24 03:02 Joffcom

Hi @Joffcom

Yeah there is a space at the end, which is getting replaced by the underscore once you download the file (weirdly not on the UI), which is exactly the issue here.

json.Projects doesn't matter here, as you can see in my reproduction, it works with '{{hello world}}.xlsx '-> hello_world.xlsx_

Nahiiko avatar Feb 16 '24 08:02 Nahiiko

Hi @Nahiiko

Seem your issue is related to your OS, Mime Type of your xlsx file is 'application/x-cfb'. This is on my server, file name works normally: n8n-convert-to-file

My server: OS: Debian 11, n8n 1.23.0 with docker

mbrother2 avatar Feb 19 '24 03:02 mbrother2

I'm running n8n inside docker on a synology NAS so I don't think that's the issue but here's the stack: postgres:15.4 n8nio/n8n:latest

Now that I think of it, I do run with "N8N_DEFAULT_BINARY_DATA_MODE: filesystem" enabled, could that be the differentiator here ?

Nahiiko avatar Feb 19 '24 08:02 Nahiiko

I don't think filesystem should matter, I do however still need to create a file with a space at the end of the extension to see what happens although that seems like it would cause other issues as it shouldn't be there anyway.

I will see if I can reproduce this now.

Joffcom avatar Feb 19 '24 08:02 Joffcom

Alright I have given this a test and the replaceAll() appears to have nothing to do with this, If you just have a space at the end of a filename we will add the _ to it instead of a space. This is likely because a trailing space in a filename will cause issues with some operating systems (Windows).

Based on this I believe this is protecting some users and there is actually no bug here as the alternative would be to remove the space from the end or refuse to download the file and throw an error.

What do you think @Nahiiko?

Joffcom avatar Feb 19 '24 09:02 Joffcom

Interesting ! indeed I didn't take the time to dig deeper and try other replacement strings, seems you're right. What a coincidence !

I think it'd make more sense to trim the space, but I guess that's just a dev choice not a bug, guess we can close.

thanks for the support!

Nahiiko avatar Feb 19 '24 12:02 Nahiiko

Hey @Nahiiko,

I think for now we can move this to closed and we can chat internally and look at what other projects do to handle it.

Joffcom avatar Feb 19 '24 13:02 Joffcom