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.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +2 -0
- data/README.md +49 -0
- data/Rakefile +7 -33
- data/lib/url_safe_base64.rb +9 -11
- data/lib/url_safe_base64/version.rb +3 -0
- data/test/url_safe_base64_test.rb +12 -12
- data/url_safe_base64.gemspec +19 -47
- metadata +63 -57
- data/README +0 -36
- data/VERSION +0 -1
- data/init.rb +0 -1
- data/lib/string_ext.rb +0 -11
- data/rails/init.rb +0 -5
- data/test/test_png.png +0 -0
checksums.yaml
ADDED
@@ -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
data/Gemfile
ADDED
data/MIT-LICENSE
CHANGED
data/README.md
ADDED
@@ -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
|
1
|
+
require "bundler/gem_tasks"
|
2
2
|
require 'rake/testtask'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
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
|
data/lib/url_safe_base64.rb
CHANGED
@@ -1,18 +1,16 @@
|
|
1
1
|
require 'base64'
|
2
|
+
require "url_safe_base64/version"
|
3
|
+
|
2
4
|
module UrlSafeBase64
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def encode64(str)
|
8
|
+
Base64.encode64(str).gsub(/[\s=]+/, "").tr('+/','-_')
|
6
9
|
end
|
7
10
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
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
|
@@ -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
|
-
|
7
|
-
|
8
|
-
|
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
|
-
"
|
12
|
-
"
|
13
|
-
"
|
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(
|
18
|
-
assert_equal
|
17
|
+
result = Base64.encode64(TEST_STRING)
|
18
|
+
assert_equal TEST_STRING_ENCODED_BASE64, result
|
19
19
|
result = Base64.decode64(result)
|
20
|
-
assert_equal
|
20
|
+
assert_equal TEST_STRING, result
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_url_safe_base64_on_png
|
24
|
-
result = UrlSafeBase64.encode64(
|
25
|
-
assert_equal
|
24
|
+
result = UrlSafeBase64.encode64(TEST_STRING)
|
25
|
+
assert_equal TEST_STRING_ENCODED_BASE64_URL, result
|
26
26
|
result = UrlSafeBase64.decode64(result)
|
27
|
-
assert_equal
|
27
|
+
assert_equal TEST_STRING, result
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_mod_groups
|
data/url_safe_base64.gemspec
CHANGED
@@ -1,51 +1,23 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
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 |
|
7
|
-
|
8
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
42
|
-
|
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
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
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
|
-
-
|
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
|
-
|
50
|
-
require_paths:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
51
65
|
- lib
|
52
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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:
|
78
|
+
rubygems_version: 2.0.3
|
74
79
|
signing_key:
|
75
|
-
specification_version:
|
76
|
-
summary: Converts strings to/from a slightly modified base64 that contains only url-safe
|
77
|
-
|
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"
|
data/lib/string_ext.rb
DELETED
data/rails/init.rb
DELETED
data/test/test_png.png
DELETED
Binary file
|