elsa-workflows / elsa-core

A .NET workflows library
https://v3.elsaworkflows.io/
MIT License
5.88k stars 1.06k forks source link

[BUG] toJson() incorrectly decodes encoded characters #5282

Open RainerAtSpirit opened 2 weeks ago

RainerAtSpirit commented 2 weeks ago

Description

This originated from this discord support question: https://discord.com/channels/814605913783795763/1232719654355599492

Steps to Reproduce

Using Elsa 3.1.2 import the encoding-issue.json and run it.

encoding-issue.json

In SetVariable an object is store in the Params variable.

return {
    german: "öäüÜÖÄß",
    secret: "Käse~!@#$%^&()_+-=/|:;'<>?,.", 
    spanish: "ñáéí"
}

In getParams() this is compared with the original string, which returns true

return getParams()?.secret === "Käse~!@#$%^&()_+-=/|:;'<>?,."

In JSON.stringify() this is compared with the original string, which returns true

JSON.parse(JSON.stringify(getParams()))?.secret === "Käse~!@#$%^&()_+-=/|:;'<>?,."

In toJson() this is compared with the original string, which returns false

JSON.parse(toJson(getParams()))?.secret === "Käse~!@#$%^&()_+-=/|:;'<>?,."

image

The writeline text Käse~!@#$%^&()_-=/|:;'//?,. is not equal to Käse~!@#$%^&()_+-=/|:;'<>?,.

Expected result: toJson() decodes encoded characters correctly.

glime-ai[bot] commented 2 weeks ago

To address the issue you're experiencing with the toJson() function not decoding encoded characters correctly, it's important to understand that toJson() is a function provided by Elsa to serialize .NET objects to JSON. The behavior you're observing, where toJson() does not return the expected result, could be due to a bug or limitation in the way Elsa handles the serialization of special characters.

Given that JSON.stringify() is working as expected, but toJson() is not, it suggests that there might be a discrepancy in how these two functions handle character encoding. Since JSON.stringify() is a standard JavaScript function and toJson() is specific to Elsa, it's possible that toJson() is not handling the encoding in the same way.

To resolve this issue, you may want to report this behavior to the Elsa team as a potential bug. You can create an issue on the Elsa GitHub repository, providing the details of your findings and the steps to reproduce the problem. The Elsa team or the community can then investigate the issue further and potentially provide a fix or a workaround.

In the meantime, if JSON.stringify() is producing the correct results, you might consider using it as a temporary solution until toJson() is fixed, provided that it meets your requirements and you are only dealing with JSON objects.

If you need further assistance or guidance, please provide additional context or clarify your specific needs, and I'll be happy to help.

This comment was generated by Glime.