From 0cb5049972f025fee6422d7f8a19424f5a686673 Mon Sep 17 00:00:00 2001 From: Michael Slone Date: Thu, 3 Oct 2013 10:32:04 -0400 Subject: [PATCH 1/8] use HTTPS instead of HTTP for RubyGems --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index c55e2d2..e9f8147 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source "http://rubygems.org" +source "https://rubygems.org" # Specify your gem's dependencies in test.gemspec gemspec From 4a3eaee9aba740d956a8f9f4c2479a833d283db1 Mon Sep 17 00:00:00 2001 From: Michael Slone Date: Thu, 3 Oct 2013 10:32:43 -0400 Subject: [PATCH 2/8] correct name of README in gemspec --- pairtree.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pairtree.gemspec b/pairtree.gemspec index ed1416c..c644ecb 100644 --- a/pairtree.gemspec +++ b/pairtree.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |s| s.email = %q{chris@cbeer.info} s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - s.extra_rdoc_files = ["LICENSE.txt", "README.textile"] + s.extra_rdoc_files = ["LICENSE.txt", "README.md"] s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] From edbf93c77e0698d8f1d87742725e2aa2ad4fa6da Mon Sep 17 00:00:00 2001 From: Michael Slone Date: Thu, 3 Oct 2013 10:46:41 -0400 Subject: [PATCH 3/8] fix link syntax in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b56d766..0872a55 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # pairtree -Ruby implementation of the [Pairtree](https://confluence.ucop.edu/display/Curation/PairTree microservice specification from the California Digital Librar) +Ruby implementation of the [Pairtree](https://confluence.ucop.edu/display/Curation/PairTree) microservice specification from the California Digital Library. # Usage From 6046f2285358db2142f18baaf92053023391eb5e Mon Sep 17 00:00:00 2001 From: Michael Slone Date: Fri, 4 Oct 2013 16:18:04 -0400 Subject: [PATCH 4/8] replace mock with double --- spec/pairtree/pairtree_obj_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/pairtree/pairtree_obj_spec.rb b/spec/pairtree/pairtree_obj_spec.rb index 3ed41a9..56172f8 100644 --- a/spec/pairtree/pairtree_obj_spec.rb +++ b/spec/pairtree/pairtree_obj_spec.rb @@ -30,7 +30,7 @@ end it "should be enumerable" do - block_body = mock('block_body') + block_body = double('block_body') block_body.should_receive(:yielded).with('content.xml') @obj.each { |file| block_body.yielded(file) } end @@ -66,4 +66,4 @@ end end -end \ No newline at end of file +end From 787e46152c1114fa22f24d5448f578ca0648c057 Mon Sep 17 00:00:00 2001 From: Michael Slone Date: Mon, 7 Oct 2013 08:47:57 -0400 Subject: [PATCH 5/8] add encoding and path --- spec/pairtree/pairtree_encoding_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/pairtree/pairtree_encoding_spec.rb b/spec/pairtree/pairtree_encoding_spec.rb index 4dd8663..9ae0c03 100644 --- a/spec/pairtree/pairtree_encoding_spec.rb +++ b/spec/pairtree/pairtree_encoding_spec.rb @@ -78,7 +78,7 @@ def roundtrip(id, expected_encoded=nil, expected_path=nil) end it "should roundtrip French" do - roundtrip('Années de Pèlerinage') + roundtrip('Années de Pèlerinage', 'Ann^c3^a9es^20de^20P^c3^a8lerinage', 'An/n^/c3/^a/9e/s^/20/de/^2/0P/^c/3^/a8/le/ri/na/ge/Ann^c3^a9es^20de^20P^c3^a8lerinage') roundtrip(%{ Années de Pèlerinage (Years of Pilgrimage) (S.160, S.161, S.163) is a set of three suites by Franz Liszt for solo piano. Liszt's From 91aacabd6050f32531ac3da986bb9cd2f35102aa Mon Sep 17 00:00:00 2001 From: Michael Slone Date: Mon, 7 Oct 2013 12:26:44 -0400 Subject: [PATCH 6/8] also test 2.0 --- .travis.yml | 1 + Gemfile | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index dd32133..609f756 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: ruby rvm: - 1.8.7 - 1.9.3 + - 2.0.0 - jruby-18mode - jruby-19mode script: bundle exec rake diff --git a/Gemfile b/Gemfile index e9f8147..bbe8004 100644 --- a/Gemfile +++ b/Gemfile @@ -5,5 +5,5 @@ gemspec gem 'rcov', :platform => :mri_18 -gem 'simplecov', :platform => :mri_19 -gem 'simplecov-rcov', :platform => :mri_19 +gem 'simplecov', :platforms => [:mri_19, :mri_20] +gem 'simplecov-rcov', :platforms => [:mri_19, :mri_20] From 5d325ab5853bdc880b3e8000a30770bf49393734 Mon Sep 17 00:00:00 2001 From: Michael Slone Date: Mon, 7 Oct 2013 12:33:55 -0400 Subject: [PATCH 7/8] make decode work in Ruby 2.0 --- lib/pairtree/identifier.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/pairtree/identifier.rb b/lib/pairtree/identifier.rb index 38f1a33..baa42cb 100644 --- a/lib/pairtree/identifier.rb +++ b/lib/pairtree/identifier.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 module Pairtree class Identifier ENCODE_REGEX = Regexp.compile("[\"*+,<=>?\\\\^|]|[^\x21-\x7e]", nil) @@ -14,7 +15,20 @@ def self.encode id # Decode special characters within an identifier # @param [String] id The identifier def self.decode id - id.tr('=+,', '/:.').gsub(DECODE_REGEX) { |h| hex2char(h) } + input = id.tr('=+,', '/:.').bytes.to_a + output = [] + while input.first + if input.first == 94 + h = [] + input.shift + h << input.shift + h << input.shift + output << h.pack('c*').hex + else + output << input.shift + end + end + output.pack('c*').force_encoding('UTF-8') end ## From 6e454eb660ab2cc4c5dc791bdd2a469fc914a915 Mon Sep 17 00:00:00 2001 From: Michael Slone Date: Mon, 7 Oct 2013 12:44:06 -0400 Subject: [PATCH 8/8] restore 1.8 support --- lib/pairtree/identifier.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/pairtree/identifier.rb b/lib/pairtree/identifier.rb index baa42cb..0ac711e 100644 --- a/lib/pairtree/identifier.rb +++ b/lib/pairtree/identifier.rb @@ -16,19 +16,23 @@ def self.encode id # @param [String] id The identifier def self.decode id input = id.tr('=+,', '/:.').bytes.to_a - output = [] + intermediate = [] while input.first if input.first == 94 h = [] input.shift h << input.shift h << input.shift - output << h.pack('c*').hex + intermediate << h.pack('c*').hex else - output << input.shift + intermediate << input.shift end end - output.pack('c*').force_encoding('UTF-8') + result = intermediate.pack('c*') + if result.respond_to? :force_encoding + result.force_encoding('UTF-8') + end + result end ##