tlossen-femto-base64-for-urls 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +38 -0
- data/Rakefile +41 -0
- data/lib/femto_base64_for_urls.rb +13 -0
- data/lib/femto_base64_for_urls/version.rb +13 -0
- data/test/test_helper.rb +10 -0
- data/test/unit/femto_base64_for_urls_test.rb +29 -0
- metadata +61 -0
data/README.rdoc
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
= FemtoBase64ForUrls
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
Describe your gem here ...
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
sudo gem install femto-base64-for-urls
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
require 'femto_base64_for_urls'
|
14
|
+
|
15
|
+
== License
|
16
|
+
|
17
|
+
Copyright (c) <year> <copyright holders>
|
18
|
+
|
19
|
+
Permission is hereby granted, free of charge, to any person
|
20
|
+
obtaining a copy of this software and associated documentation
|
21
|
+
files (the "Software"), to deal in the Software without
|
22
|
+
restriction, including without limitation the rights to use,
|
23
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
24
|
+
copies of the Software, and to permit persons to whom the
|
25
|
+
Software is furnished to do so, subject to the following
|
26
|
+
conditions:
|
27
|
+
|
28
|
+
The above copyright notice and this permission notice shall be
|
29
|
+
included in all copies or substantial portions of the Software.
|
30
|
+
|
31
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
32
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
33
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
34
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
35
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
36
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
37
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
38
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
require 'lib/femto_base64_for_urls/version'
|
6
|
+
|
7
|
+
task :default => :test
|
8
|
+
|
9
|
+
spec = Gem::Specification.new do |s|
|
10
|
+
s.name = 'femto-base64-for-urls'
|
11
|
+
s.version = FemtoBase64ForUrls::Version.to_s
|
12
|
+
s.has_rdoc = true
|
13
|
+
s.extra_rdoc_files = %w(README.rdoc)
|
14
|
+
s.rdoc_options = %w(--main README.rdoc)
|
15
|
+
s.summary = %Q{A modified variant of Base64 suitable for use in URLs:
|
16
|
+
no padding '=' is used, and the '+' and '/' characters of standard Base64
|
17
|
+
are replaced by '-' and '_'.}
|
18
|
+
s.author = 'Tim Lossen, François Wurmus'
|
19
|
+
s.email = 'tim@lossen.de'
|
20
|
+
s.homepage = 'http://tim.lossen.de'
|
21
|
+
s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
|
22
|
+
# s.executables = ['femto-base64-for-urls']
|
23
|
+
# s.add_dependency('gem_name', '~> 0.0.1')
|
24
|
+
end
|
25
|
+
|
26
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
27
|
+
pkg.gem_spec = spec
|
28
|
+
end
|
29
|
+
|
30
|
+
Rake::TestTask.new do |t|
|
31
|
+
t.libs << 'test'
|
32
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
33
|
+
t.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'Generate the gemspec to serve this Gem from Github'
|
37
|
+
task :github do
|
38
|
+
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
|
39
|
+
File.open(file, 'w') {|f| f << spec.to_ruby }
|
40
|
+
puts "Created gemspec: #{file}"
|
41
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module Base64
|
4
|
+
def url_encode64(text)
|
5
|
+
encode64(text).chomp.gsub('=','').gsub('+','-').gsub('/','_')
|
6
|
+
end
|
7
|
+
|
8
|
+
def url_decode64(text)
|
9
|
+
modulo = text.length % 4
|
10
|
+
padding = (modulo == 0) ? '' : '=' * (4 - modulo)
|
11
|
+
decode64(text.gsub('-','+').gsub('_','/') + padding)
|
12
|
+
end
|
13
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class FemtoBase64ForUrlsTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
describe 'module Base64' do
|
6
|
+
it "should encode a string into url-safe base64" do
|
7
|
+
Base64.url_encode64("#\360").should == 'I_A'
|
8
|
+
Base64.url_encode64("#\340").should == 'I-A'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should decode a url-safe base64 string" do
|
12
|
+
Base64.url_decode64('I_A').should == "#\360"
|
13
|
+
Base64.url_decode64('I-A').should == "#\340"
|
14
|
+
Base64.url_decode64('I-A=').should == "#\340"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should work in roundtrip" do
|
18
|
+
16.times do
|
19
|
+
bytes = ''
|
20
|
+
(rand(32) + 8).times { bytes << rand(256) }
|
21
|
+
encoded = Base64.url_encode64(bytes)
|
22
|
+
encoded.index('+').should be_nil
|
23
|
+
encoded.index('/').should be_nil
|
24
|
+
Base64.url_decode64(encoded).should == bytes
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tlossen-femto-base64-for-urls
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Tim Lossen, Fran\xC3\xA7ois Wurmus"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-20 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: tim@lossen.de
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- Rakefile
|
27
|
+
- lib/femto_base64_for_urls
|
28
|
+
- lib/femto_base64_for_urls/version.rb
|
29
|
+
- lib/femto_base64_for_urls.rb
|
30
|
+
- test/test_helper.rb
|
31
|
+
- test/unit
|
32
|
+
- test/unit/femto_base64_for_urls_test.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://tim.lossen.de
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --main
|
38
|
+
- README.rdoc
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.2.0
|
57
|
+
signing_key:
|
58
|
+
specification_version: 2
|
59
|
+
summary: "A modified variant of Base64 suitable for use in URLs: no padding '=' is used, and the '+' and '/' characters of standard Base64 are replaced by '-' and '_'."
|
60
|
+
test_files: []
|
61
|
+
|