url_safe_base64 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2947844daa2fda05344d0ced6e0af9b30528c11f
4
+ data.tar.gz: b4cd77f1cc39c91b9d46d5e292bf73d91f8d971d
5
+ SHA512:
6
+ metadata.gz: b40694782d7084edacddd64c64ab0f0e41a04f8e418fbd0534e569ec648c825446d5b5c50dc30a4f28d551a7e5e069a440e2c34d48eb5a5d637598f2c6d1061c
7
+ data.tar.gz: 0a909915528ced9c87c429694b343bf62b3c1da98e86389f657e517904403e622711e3d864877e8f68f2d9c0aca9ecbd56c002fbecc01ff1dbd229a3ccd1583b
data/.gitignore CHANGED
@@ -1 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
1
12
  pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in x1.gemspec
4
+ gemspec
@@ -1,5 +1,7 @@
1
1
  Copyright (c) 2008 Joe Noon
2
2
 
3
+ MIT License
4
+
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
5
7
  "Software"), to deal in the Software without restriction, including
@@ -0,0 +1,49 @@
1
+ # UrlSafeBase64
2
+
3
+ Copyright (c) 2008 Joe Noon, released under the MIT license
4
+
5
+ Converts strings to/from a slightly modified base64 that contains only url-safe characters
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'url_safe_base64'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install url_safe_base64
20
+
21
+ ## Usage
22
+
23
+ Normal Base64:
24
+
25
+ ```ruby
26
+ Base64.encode64 "Test string" #=> "VGVzdCBzdHJpbmc=\n"
27
+ ```
28
+
29
+ ```ruby
30
+ Base64.decode64 "VGVzdCBzdHJpbmc=\n" #=> "Test string"
31
+ ```
32
+
33
+ With this gem:
34
+
35
+ ```ruby
36
+ UrlSafeBase64.encode64 "Test string" #=> "VGVzdCBzdHJpbmc"
37
+ ```
38
+
39
+ ```ruby
40
+ UrlSafeBase64.decode64 "VGVzdCBzdHJpbmc=\n" #=> "Test string"
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,36 +1,10 @@
1
- require 'rake'
1
+ require "bundler/gem_tasks"
2
2
  require 'rake/testtask'
3
- require 'rake/rdoctask'
4
-
5
- desc 'Default: run unit tests.'
6
- task :default => :test
7
-
8
- desc 'Test the url_safe_base64 plugin.'
9
- Rake::TestTask.new(:test) do |t|
10
- t.libs << 'lib'
11
- t.pattern = 'test/**/*_test.rb'
12
- t.verbose = true
3
+ Rake::TestTask.new(:test) do |test|
4
+ test.libs << 'test'
5
+ test.warning = true
6
+ test.verbose = true
7
+ test.pattern = 'test/**/*_test.rb'
13
8
  end
14
9
 
15
- desc 'Generate documentation for the url_safe_base64 plugin.'
16
- Rake::RDocTask.new(:rdoc) do |rdoc|
17
- rdoc.rdoc_dir = 'rdoc'
18
- rdoc.title = 'UrlSafeBase64'
19
- rdoc.options << '--line-numbers' << '--inline-source'
20
- rdoc.rdoc_files.include('README')
21
- rdoc.rdoc_files.include('lib/**/*.rb')
22
- end
23
-
24
- begin
25
- require 'jeweler'
26
- Jeweler::Tasks.new do |gemspec|
27
- gemspec.name = "url_safe_base64"
28
- gemspec.summary = "Converts strings to/from a slightly modified base64 that contains only url-safe characters"
29
- gemspec.description = "Converts strings to/from a slightly modified base64 that contains only url-safe characters"
30
- gemspec.email = "joenoon@gmail.com"
31
- gemspec.homepage = "http://github.com/joenoon/url_safe_base64"
32
- gemspec.authors = ["Joe Noon"]
33
- end
34
- rescue LoadError
35
- puts "Jeweler not available. Install it with: gem install jeweler"
36
- end
10
+ task :default => :test
@@ -1,18 +1,16 @@
1
1
  require 'base64'
2
+ require "url_safe_base64/version"
3
+
2
4
  module UrlSafeBase64
3
-
4
- def self.encode64(str)
5
- Base64.encode64(str).gsub(/[\s=]+/, "").gsub("+", "-").gsub("/", "_")
5
+ extend self
6
+
7
+ def encode64(str)
8
+ Base64.encode64(str).gsub(/[\s=]+/, "").tr('+/','-_')
6
9
  end
7
10
 
8
- def self.decode64(str)
9
- case str.length.modulo(4)
10
- when 2
11
- str += '=='
12
- when 3
13
- str += '='
14
- end
15
- Base64.decode64(str.gsub("-", "+").gsub("_", "/"))
11
+ def decode64(str)
12
+ str += '=' * (4 - str.length.modulo(4))
13
+ Base64.decode64(str.tr('-_','+/'))
16
14
  end
17
15
 
18
16
  end
@@ -0,0 +1,3 @@
1
+ module UrlSafeBase64
2
+ VERSION = "0.2.2"
3
+ end
@@ -3,28 +3,28 @@ require File.join(File.dirname(__FILE__),"..","lib","url_safe_base64.rb")
3
3
 
4
4
  class UrlSafeBase64Test < Test::Unit::TestCase
5
5
 
6
- TEST_FILE = File.read(File.join(File.dirname(__FILE__),"test_png.png"))
7
- TEST_NORM_ENCODE64 = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAGXRFWHRTb2Z0\nd2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAjpJREFUeNpMUs9LG1EQnmw2\n260lalIqadIVqSHQNpKAGL2JBoTSBkIPuXnqyUvAP0JPgvVQ8JZa6NFADoGI\n6UHwaEBUSE2kJErp2nSbXek2+yN56+RtNnQYlvdmvm/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l-VNfHOx0kdAEM6oTj3pdKzxcX-4RcKlUrFh8CNAIBEotNhsNis8mcnLwSRZO-oAN0AJ5Eo9lKhRXPz79RtOz1epeWVtfXPR4PdvVlZ-dnoRCUZbsZrE28uKgdHDD1w0OGFi36fIlkEtOGYUiS9GJ-vunzsU5LbuoIZuWbm8GdEFPTTBN7UVRVlSWJJcTloO2fytfXbFfXbb2EdvtrPv_I7we3-0-rVSmXI-22Xc9wUl3TZMdCIVs-v6r-PTv7tLHhm5hQWq3I7e3Tu7suTRHHR4NB14_T0w_xOAqK_oBW_I_KylhWj8pqUllRJQ1gdX-fCczMTOIQnAR-eU3rWZZB1RwGkTkmCJGVFewE3m5vWxynU4SN0x30MILnN1tbbo7rE4S5uUwuh7PU6Lv2mDpOGRrlvN7cjKbTg9Ww969xfJxfW8M9dTvLZ4sxLghYwstUymXbkIBGej3c1nq53G40TMPwT01NJ5NYNzcygkh7ve8FGACA_yuDGxf1iwAAAABJRU5ErkJggg"
6
+ TEST_STRING = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 !@#$%^&*()-=_+/?.:;[]{}\|"
7
+ TEST_STRING_ENCODED_BASE64 = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXogQUJDREVGR0hJSktMTU5PUFFS\nU1RVVldYWVogMTIzNDU2Nzg5MCAhQCMkJV4mKigpLT1fKy8/Ljo7W117fXw=\n"
8
+ TEST_STRING_ENCODED_BASE64_URL = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXogQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVogMTIzNDU2Nzg5MCAhQCMkJV4mKigpLT1fKy8_Ljo7W117fXw"
9
9
 
10
10
  MOD_GROUPS = {
11
- "0" => [TEST_FILE+'AB', TEST_FILE+'ABCDE'],
12
- "2" => [TEST_FILE, TEST_FILE+'ABC'],
13
- "3" => [TEST_FILE+'A', TEST_FILE+'ABCD']
11
+ "2" => [TEST_STRING+'AB', TEST_STRING+'ABCDE'],
12
+ "3" => [TEST_STRING, TEST_STRING+'ABC'],
13
+ "0" => [TEST_STRING+'A', TEST_STRING+'ABCD']
14
14
  }
15
15
 
16
16
  def test_the_test
17
- result = Base64.encode64(TEST_FILE)
18
- assert_equal TEST_NORM_ENCODE64, result
17
+ result = Base64.encode64(TEST_STRING)
18
+ assert_equal TEST_STRING_ENCODED_BASE64, result
19
19
  result = Base64.decode64(result)
20
- assert_equal TEST_FILE, result
20
+ assert_equal TEST_STRING, result
21
21
  end
22
22
 
23
23
  def test_url_safe_base64_on_png
24
- result = UrlSafeBase64.encode64(TEST_FILE)
25
- assert_equal TEST_SAFE_EXPECTED, result
24
+ result = UrlSafeBase64.encode64(TEST_STRING)
25
+ assert_equal TEST_STRING_ENCODED_BASE64_URL, result
26
26
  result = UrlSafeBase64.decode64(result)
27
- assert_equal TEST_FILE, result
27
+ assert_equal TEST_STRING, result
28
28
  end
29
29
 
30
30
  def test_mod_groups
@@ -1,51 +1,23 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'url_safe_base64/version'
5
5
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{url_safe_base64}
8
- s.version = "0.2.1"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "url_safe_base64"
8
+ spec.version = UrlSafeBase64::VERSION
9
+ spec.authors = ["Joe Noon"]
10
+ spec.email = ["joenoon@gmail.com"]
11
+ spec.description = %q{Converts strings to/from a slightly modified base64 that contains only url-safe characters}
12
+ spec.summary = %q{Converts strings to/from a slightly modified base64 that contains only url-safe characters}
13
+ spec.homepage = "http://github.com/joenoon/url_safe_base64"
14
+ spec.license = "MIT"
9
15
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Joe Noon"]
12
- s.date = %q{2010-07-22}
13
- s.description = %q{Converts strings to/from a slightly modified base64 that contains only url-safe characters}
14
- s.email = %q{joenoon@gmail.com}
15
- s.extra_rdoc_files = [
16
- "README"
17
- ]
18
- s.files = [
19
- ".gitignore",
20
- "MIT-LICENSE",
21
- "README",
22
- "Rakefile",
23
- "VERSION",
24
- "init.rb",
25
- "lib/string_ext.rb",
26
- "lib/url_safe_base64.rb",
27
- "rails/init.rb",
28
- "test/test_png.png",
29
- "test/url_safe_base64_test.rb",
30
- "url_safe_base64.gemspec"
31
- ]
32
- s.homepage = %q{http://github.com/joenoon/url_safe_base64}
33
- s.rdoc_options = ["--charset=UTF-8"]
34
- s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.3.7}
36
- s.summary = %q{Converts strings to/from a slightly modified base64 that contains only url-safe characters}
37
- s.test_files = [
38
- "test/url_safe_base64_test.rb"
39
- ]
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
40
20
 
41
- if s.respond_to? :specification_version then
42
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
- s.specification_version = 3
44
-
45
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
- else
47
- end
48
- else
49
- end
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
50
23
  end
51
-
metadata CHANGED
@@ -1,78 +1,84 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: url_safe_base64
3
- version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Joe Noon
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2010-07-22 00:00:00 -07:00
19
- default_executable:
20
- dependencies: []
21
-
22
- description: Converts strings to/from a slightly modified base64 that contains only url-safe characters
23
- email: joenoon@gmail.com
11
+ date: 2013-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Converts strings to/from a slightly modified base64 that contains only
42
+ url-safe characters
43
+ email:
44
+ - joenoon@gmail.com
24
45
  executables: []
25
-
26
46
  extensions: []
27
-
28
- extra_rdoc_files:
29
- - README
30
- files:
47
+ extra_rdoc_files: []
48
+ files:
31
49
  - .gitignore
50
+ - Gemfile
32
51
  - MIT-LICENSE
33
- - README
52
+ - README.md
34
53
  - Rakefile
35
- - VERSION
36
- - init.rb
37
- - lib/string_ext.rb
38
54
  - lib/url_safe_base64.rb
39
- - rails/init.rb
40
- - test/test_png.png
55
+ - lib/url_safe_base64/version.rb
41
56
  - test/url_safe_base64_test.rb
42
57
  - url_safe_base64.gemspec
43
- has_rdoc: true
44
58
  homepage: http://github.com/joenoon/url_safe_base64
45
- licenses: []
46
-
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
47
62
  post_install_message:
48
- rdoc_options:
49
- - --charset=UTF-8
50
- require_paths:
63
+ rdoc_options: []
64
+ require_paths:
51
65
  - lib
52
- required_ruby_version: !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
61
- required_rubygems_version: !ruby/object:Gem::Requirement
62
- none: false
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- hash: 3
67
- segments:
68
- - 0
69
- version: "0"
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
70
76
  requirements: []
71
-
72
77
  rubyforge_project:
73
- rubygems_version: 1.3.7
78
+ rubygems_version: 2.0.3
74
79
  signing_key:
75
- specification_version: 3
76
- summary: Converts strings to/from a slightly modified base64 that contains only url-safe characters
77
- test_files:
80
+ specification_version: 4
81
+ summary: Converts strings to/from a slightly modified base64 that contains only url-safe
82
+ characters
83
+ test_files:
78
84
  - test/url_safe_base64_test.rb
data/README DELETED
@@ -1,36 +0,0 @@
1
- UrlSafeBase64
2
- =============
3
-
4
- Converts strings to/from a slightly modified base64 that contains only url-safe characters
5
-
6
- Examples
7
- ========
8
-
9
- Normal:
10
-
11
- >> "Test string".url_safe_encode64
12
- => "VGVzdCBzdHJpbmc"
13
-
14
- >> Base64.encode64 "Test string"
15
- => "VGVzdCBzdHJpbmc=\n"
16
-
17
- >> Base64.decode64 "VGVzdCBzdHJpbmc=\n"
18
- => "Test string"
19
-
20
- With this gem:
21
-
22
- >> UrlSafeBase64.encode64 "Test string"
23
- => "VGVzdCBzdHJpbmc"
24
-
25
- >> UrlSafeBase64.decode64 "VGVzdCBzdHJpbmc=\n"
26
- => "Test string"
27
-
28
- Or:
29
-
30
- >> "Test string".url_safe_encode64
31
- => "VGVzdCBzdHJpbmc"
32
-
33
- >> "VGVzdCBzdHJpbmc".url_safe_decode64
34
- => "Test string"
35
-
36
- Copyright (c) 2008 Joe Noon, released under the MIT license
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.1
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require File.dirname(__FILE__) + "/rails/init"
@@ -1,11 +0,0 @@
1
- module Statim
2
- module UrlSafeBase64StringExtension
3
- def url_safe_encode64
4
- UrlSafeBase64.encode64(self)
5
- end
6
-
7
- def url_safe_decode64
8
- UrlSafeBase64.decode64(self)
9
- end
10
- end
11
- end
@@ -1,5 +0,0 @@
1
- require 'url_safe_base64'
2
- require 'string_ext'
3
- unless String.included_modules.include?(Statim::UrlSafeBase64StringExtension)
4
- String.send :include, Statim::UrlSafeBase64StringExtension
5
- end
Binary file