<commit_before># encoding: utf-8
require 'spec_helper'

describe Dragonfly::Serializer do

  include Dragonfly::Serializer

  describe "base 64 encoding/decoding" do
    [
      'a',
      'sdhflasd',
      '/2010/03/01/hello.png',
      '//..',
      'whats/up.egg.frog',
      '£ñçùí;',
      '~',
      '-umlaut_ö'
    ].each do |string|
      it "should encode #{string.inspect} properly with no padding/line break or slash" do
        b64_encode(string).should_not =~ /\n|=|\//
      end
      it "should correctly encode and decode #{string.inspect} to the same string" do
        str = b64_decode(b64_encode(string))
        str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
        str.should == string
      end
    end

    describe "b64_decode" do
      it "converts (deprecated) '~' and '/' characters to '_' characters" do
        b64_decode('LXVtbGF1dF~Dtg').should == b64_decode('LXVtbGF1dF/Dtg')
        b64_decode('LXVtbGF1dF/Dtg').should == b64_decode('LXVtbGF1dF_Dtg')
      end
    end
  end

  describe "marshal_b64_decode" do
    it "should raise an error if the string passed in is empty" do
      lambda{
        marshal_b64_decode('')
      }.should raise_error(Dragonfly::Serializer::BadString)
    end
    it "should raise an error if the string passed in is gobbledeegook" do
      lambda{
        marshal_b64_decode('ahasdkjfhasdkfjh')
      }.should raise_error(Dragonfly::Serializer::BadString)
    end
    describe "potentially harmful strings" do
      ['_', 'hello', 'h2', '__send__', 'F'].each do |variable_name|
        it "raises if it finds a malicious string" do
          class C; end<commit_msg>didn't have a test for bad base 64 encoded string in serializer_spec<commit_after># encoding: utf-8
require 'spec_helper'

describe Dragonfly::Serializer do

  include Dragonfly::Serializer

  describe "base 64 encoding/decoding" do
    [
      'a',
      'sdhflasd',
      '/2010/03/01/hello.png',
      '//..',
      'whats/up.egg.frog',
      '£ñçùí;',
      '~',
      '-umlaut_ö'
    ].each do |string|
      it "should encode #{string.inspect} properly with no padding/line break or slash" do
        b64_encode(string).should_not =~ /\n|=|\//
      end
      it "should correctly encode and decode #{string.inspect} to the same string" do
        str = b64_decode(b64_encode(string))
        str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
        str.should == string
      end
    end

    describe "b64_decode" do
      it "raises an error if the string passed in is not base 64" do
        expect {
          b64_decode("eggs for breakfast")
        }.to raise_error(Dragonfly::Serializer::BadString)
      end
      it "converts (deprecated) '~' and '/' characters to '_' characters" do
        b64_decode('LXVtbGF1dF~Dtg').should == b64_decode('LXVtbGF1dF/Dtg')
        b64_decode('LXVtbGF1dF/Dtg').should == b64_decode('LXVtbGF1dF_Dtg')
      end
    end
  end

  describe "marshal_b64_decode" do
    it "should raise an error if the string passed in is empty" do
      lambda{
        marshal_b64_decode('')
      }.should raise_error(Dragonfly::Serializer::BadString)
    end
    it "should raise an error if the string passed in is gobbledeegook" do
      lambda{
        marshal_b64_decode('ahasdkjfhasdkfjh')
      }.should raise_error(Dragonfly::Serializer::BadString)
    end
    describe "potentially harmful strings" do
      ['_', 'hello', 'h2', '__send__', 'F'].each do |variable_name|
        it "raises if it finds a malicious string" do
          class C; end
{'fraction_non_alphanumeric': 0.11652124964818464, 'fraction_numerical': 0.023641992682240362, 'mean_word_length': 2.7529039070749737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4648835', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1162, 'n_words': 311}