dragonfly icon indicating copy to clipboard operation
dragonfly copied to clipboard

Base64 serialization violates url structure

Open DimaSamodurov opened this issue 15 years ago • 3 comments

I got this issue having "French" symbol in the image name. It worked in some case but in different case (different character sequences) it didn't. Looking deeper i found that it's job serialization issue.

Job uses Serializer.marshal_encode method returns Base64 encoded string. Problem that "/" character is present in Base64 alphabet.

For instanse:

Dragonfly::Serializer.marshal_encode((127..255).map(&:chr).join) 

produces string which contains "/" character: BAgiAYF/gIGCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+v8DBwsPExcbHyMnKy8zNzs/Q0dLT1NXW19jZ2tvc3d7f4OHi4+Tl5ufo6err7O3u7/Dx8vP09fb3+Pn6+/z9/v8

This brakes default url parsing routines. Most likely you'll have routing error.

I think it's necessary to update Job.serialize to avoid "/" in result. Important to preserve backward compatibility with correct urls generated previously.

We can additionally replace "/" character with non Base64 but url safe character like "_". And perform inverse operation on deserialize.

Or if it's safe, fix Serializer.b64_decode / b64_encode methods the same way.

DimaSamodurov avatar May 12 '11 13:05 DimaSamodurov

Thanks for looking at this strangely that's the first time I've come across a '/' in the string You're right that the way to get around it is to translate '/' to '_' or something like that I'll have a look over the next day or so Cheers

markevans avatar May 12 '11 14:05 markevans

Hi this is fixed here: 3e6f5edd74f65db31eb598d7d63bbe8e7c67749b (sorry for the delay!) it will be included in the next gem release

markevans avatar Jun 03 '11 09:06 markevans

Thanks a lot! No problem, i used a patch with alias_method_chain and very similar test :). I had better publish a gist.

DimaSamodurov avatar Jun 03 '11 16:06 DimaSamodurov