Skip to main content
jisaitua
Silver ⭐️⭐️
June 21, 2023
Solved

Escaping EL Issue

We are having escaping issues in some expressions. Just an example (using Nifi 1.21.0):

ExpressionValue

{"$${key}": "value"}

{"${key}": "value"}

{"$${key}": "${literal('value')}"}

{"$${key}": "value"}

As one can see, the second expression is not escaping the dollar sign as it should (from the docs, see "Escaping Expression Language"), and just stays as "$$".

Any comments/hints would be much appreciated.

MattWho
MattWhoAnswer
Titanium ⭐️⭐️⭐️
June 21, 2023

@jisaitua 

Definitely some weird unexpected behavior there. I was able to reproduce your issue, as well as some other unexpected behavior around same area.

As a workaround to your specific issue, the following NiFi Expression Language (NEL) will get you what you are looking for:

{${literal('')}"$${key}":"${literal('value')}"}


I also filed an Apache NiFi jira for this issue:
https://issues.apache.org/jira/browse/NIFI-11738

 

I reproduced on an Apache NiFi 1.18 cluster I have running, so it is not an issue that just recently appeared.

If you found that the provided solution(s) assisted you with your query, please take a moment to login and click Accept as Solution below each response that helped.

Thank you,

Matt



2 replies

MattWho
Titanium ⭐️⭐️⭐️
MattWhoAnswer
Titanium ⭐️⭐️⭐️
June 21, 2023

@jisaitua 

Definitely some weird unexpected behavior there. I was able to reproduce your issue, as well as some other unexpected behavior around same area.

As a workaround to your specific issue, the following NiFi Expression Language (NEL) will get you what you are looking for:

{${literal('')}"$${key}":"${literal('value')}"}


I also filed an Apache NiFi jira for this issue:
https://issues.apache.org/jira/browse/NIFI-11738

 

I reproduced on an Apache NiFi 1.18 cluster I have running, so it is not an issue that just recently appeared.

If you found that the provided solution(s) assisted you with your query, please take a moment to login and click Accept as Solution below each response that helped.

Thank you,

Matt



Translate
jisaitua
jisaituaAuthor
Silver ⭐️⭐️
June 21, 2023

Thank you @MattWho, the trick worked! Sadly, it worked for this simple case, but for more complex cases we couldn't find a pattern to apply it. However, we found another workaround by using literals like this:

ExpressionValue

{
"${literal('$${key1}')}": "${literal('$${value1}')}",
"key2": "${literal('$${value2}')}",
"${literal('$${key3}')}": "value3",
"key4": "${literal('value4')}"
}

{
"${key1}": "${value1}",
"key2": "${value2}",
"${key3}": "value3",
"key4": "value4"
}


It's a nasty hack, but it gets the job done! Thanks again for your help and for filling a bug report.

Translate