I recently had an issue that a Constant that was copy-pasted had a ZeroWidthSpace in it.
(see Whitespace character - Wikipedia )
This prevented our app to connect with an API as the URL was incorrect.
The problem with these characters is that they are not shown on the screen and will not show up in logging. The only way to find it is to copy-paste the text from the screen or log to an editor such as Notepad++ in which you have the option to shown these characters.
Here is an example:
Left is the string in Notepad, right is the same string in Notepad++ with the 'show all characters' option on.
While I think these characters should be removed when setting a constant in the Mendix Cloud, I also want to add my solution to others to prevent problems such as these.
The solution is to replace all whitespace characters by using a RegEx:
replaceAll(@Module.constant,'\p{Cf}','')
I think this should be added to the StringTrim Java action in de Community Commons to make it more complete.
And @Mendix, please use this before saving the constant in the cloud
Thank you for the comment.
I am unsure why you would use a constant for that. It is unlikely that that constant would be different on each environment, is it?
What would be your suggestion?
Leave the JA Trim as it is and create a new JA in Community Commons?
e.g. TrimWhitespace?
While I understand the frustration that can be caused by the ZWSP character (had my own headaches with that already) I don't agree on this proposal.
1. The platform should NOT silently trim constants - image I was using a constant to define a set of whitespace character.
2. Community Commons uses Java's String.trim. That behaviour is well defined and the module should stick to that.