I have a problem with the encoding of image URLs on my website and I tried 2 different encoding methods but they both have problems. For example my image file has the following name: "Some special Characters;.jpg"
If I use URLEncoder.encode(imageName, "UTF-8");
I get the following URL:
/some/url/Some+special+Characters%3B_92631.jpg
If I use UrlEscapers.urlPathSegmentEscaper().escape(imageName)
I get:
/some/url/Some%20special%20Characters;_63414.jpg
I tried to find the correct URL of the image and I found this one:
/some/url/Some%20special%20Characters%3B_63414.jpg
It looks like URLEncoder is not encoding spaces correctly while URLEscapers does not encode the semicolon. Other special characters like ! or , work without any problems.
How can I encode my URL correctly?