Some kind of overlay texts generate urls which cause `400 Bad Request`
Some kind of overlay texts generate urls which cause 400 Bad Request
Describe the bug in a sentence or two.
require 'open-uri'
def foo(text)
url = Cloudinary::Utils.cloudinary_url('sample', transformation: [
{
overlay: {
font_size: 24,
font_family: 'Sawarabi%20Gothic',
text: text
},
}
])
URI.open(url)
end
foo('hello') # No problem
foo('hello🍺') # => 400 Bad Request (OpenURI::HTTPError)
Issue Type (Can be multiple)
- [ ] Build - Cannot install or import the SDK
- [ ] Performance - Performance issues
- [x] Behaviour - Functions are not working as expected (such as generate URL)
- [x] Documentation - Inconsistency between the docs and behaviour
- [ ] Other (Specify)
Operating System
- [ ] Linux
- [ ] Windows
- [ ] macOS
- [x] All
Environment and Libraries (fill in the version numbers)
$ bundle info cloudinary
* cloudinary (1.21.0)
Summary: Client library for easily using the Cloudinary service
Homepage: http://cloudinary.com
Path: /Users/ttanimichi/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/cloudinary-1.21.0
$ ruby -v
ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [arm64-darwin21]
$ bin/rails -v
Rails 6.1.4.1
Hi @ttanimichi, including emojis in text overlays can be done by double encoding the emoji as explained here:https://support.cloudinary.com/hc/en-us/articles/360003457091-How-to-overlay-emojis-in-images. Please note that not all emojis are supported. You can refer here for the list of supported emojis: https://www.piliapp.com/symbol/
@michalkcloudinay Thank you for your reply. Not only emojis but also some kind of chinese characters seem to cause the same error.
foo('漢字') # Most of chinese characters are No Problem
foo('あいうえお') # Japanese Hiragana letters are also No Problem
foo('𩸽') # => 400 Bad Request (OpenURI::HTTPError)
foo('𡈽') # => 400 Bad Request (OpenURI::HTTPError)
foo('𠀋') # => 400 Bad Request (OpenURI::HTTPError)
I found that the bytesize of 🍺, 𩸽 (Unicode: U+29E3D), 𡈽 and 𠀋 are four.
$ irb
irb(main):001:0> '𩸽'.bytesize
=> 4
irb(main):002:0> '🍺'.bytesize
=> 4
irb(main):003:0> '𡈽'.bytesize
=> 4
irb(main):004:0> '𠀋'.bytesize
=> 4
Probably, overlay texts of 4-bytesize Unicode characters cause this error. Isn't it a bug of Cloudinary API, is it?
One of my best friend Mr. 𡈽田 (Tsuchida) can't display his name as overlay texts since his family name contains 𡈽, which is a 4-bytesize Unicode character. It's so much trouble for him...
Hi @ttanimichi, for 4-bytesize Unicode characters you would need to use a double encoding. For example: https://res.cloudinary.com/demo/image/upload/o_30/l_text:Arial_58:%2520%25F0%25A9%25B8%25BD/couple.jpg Let us know if this works for you.
@michalkcloudinay Thanks! I'll try it next week and let you know the result
Great! Let us know how it goes.
Hi @ttanimichi - just wanted to follow up on this to see if you had a chance to test this and if it worked for you?