Have other UrlEncode options to get more robust implementations - Mendix Forum

Have other UrlEncode options to get more robust implementations


From w3schools the following statement is applicable. (https://www.w3schools.com/tags/ref_urlencode.ASP)
URLs can only be sent over the Internet using the ASCII character-set.
Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format.
URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits.
URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.

In the Mendix documentation, the following statement is shared. (https://docs.mendix.com/refguide/string-function-calls#a-name-urlencode-a-urlencode)
Converts a string to be used in a URL. This function is useful when you want to use the string as part of the URL.

However, this has led to bad requests from our side, because of the different encoding and decoding functions available but when having a %20 mark, everything worked OK.

Could this be changed or implemented in a way that is different or configurable?

So, either use %20 as default for a more robust implementation or have it as an option in the function itself
urlEncode($var, 'implementationA')
urlEncode($var, 'implementationB')


2 answers

That is one of the workarounds that can be used. I'm unsure if the 'space’-character is the only one causing any specific problems. The current (better?) solution I found is to use an external library like for example UriUtils to be more sure. Still, I think this is better implemented by Mendix so makers do not have to think about these kinds of options. Especially when Mendix states that the urlEncode should be used for paths.


I guess you’re using replaceAll(urlEncode($var), ‘+’, ‘%20’) now, right?