views:

460

answers:

2

Hello,

I have base64-encoded string (with two dollar signs, so it's not a common base64 string)

The problem: Base64.decode64 (or .unpack("m")) decodes it just fine on my local machine(ruby 1.8.6), but with ruby 1.8.5 (the version used by Heroku) it doesn't work

Any ideas ?

edit:

I have :

$$YTo1OntzOjM6Im1pZCI7czo3OiI3MTE5Njg3IjtzOjQ6Im5hbWUiO3M6MjE6IkthbnllIFdlc3QgLSBTdHJvbmd lciI7czo0OiJsaW5rIjtzOjQ4OiJodHRwOi8vd3d3LmVhc3kxNS5jb20vMDIgU3Ryb25nZXIgKFNuaXBwZXQpMS5tcD MiO3M6OToiX3BsYXl0aW1lIjtzOjU6IjgzMjAwIjtzOjg6Il9uZXh0aWRzIjtzOjEzNDoiMjc1ODE0MDYsMjc0MDE1 NzAsMjI1MTU0MDMsMTU1ODM2NjYsMTYzMTUzMzksMjgwNDY5MTUsMzAzOTMxODksMzUyMDAyMTMsMjIwNTE1MzAsMj c1NTg1MTQsMTM3ODkyNTYsMTk4MTY5OTgsMzA0NzI4MDEsMTUyNTk5NzksMTg5OTkxMzciO30=

I successed in decoding it with '...'.unpack("m") locally but not on the heroku server (ruby 1.8.5, maybe the ruby version it's not the issue)

+1  A: 

@Gumbo

I have :

$$YTo1OntzOjM6Im1pZCI7czo3OiI3MTE5Njg3IjtzOjQ6Im5hbWUiO3M6MjE6IkthbnllIFdlc3QgLSBTdHJvbmdlciI7czo0OiJsaW5rIjtzOjQ4OiJodHRwOi8vd3d3LmVhc3kxNS5jb20vMDIgU3Ryb25nZXIgKFNuaXBwZXQpMS5tcDMiO3M6OToiX3BsYXl0aW1lIjtzOjU6IjgzMjAwIjtzOjg6Il9uZXh0aWRzIjtzOjEzNDoiMjc1ODE0MDYsMjc0MDE1NzAsMjI1MTU0MDMsMTU1ODM2NjYsMTYzMTUzMzksMjgwNDY5MTUsMzAzOTMxODksMzUyMDAyMTMsMjIwNTE1MzAsMjc1NTg1MTQsMTM3ODkyNTYsMTk4MTY5OTgsMzA0NzI4MDEsMTUyNTk5NzksMTg5OTkxMzciO30=

I successed in decoding it with '...'.unpack("m") locally but not on the heroku server (ruby 1.8.5, maybe the ruby version it's not the issue)

Gaetan Dubar
You better edit your initial question.
Gumbo
+3  A: 

The dollar sign is not part of the Base64 specification.

Simply strip the leading $$ before unpacking:

str.sub(/^\$*/, '').unpack('m')

To strip all non-Base64 characters, emulating new (Ruby 1.8.6) behaviour,

str.gsub(/[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\+\/]/, '').unpack('m')

Ruby 1.8.6 will ignore all non-Base64 symbols (including the $) inside the string to decode, whereas 1.8.5 will stop processing at the first such character (see pack.c in the Ruby source.)

Cheers, V.

vladr