Commits

Michael Granger  committed aed1590

Added a spec for, and fixed some bugs in the URI backport monkeypatch.

  • Participants
  • Parent commits c54e4bb

Comments (0)

Files changed (4)

File lib/axis/monkeypatches.rb

 			TBLENCWWWCOMP_[' '] = '+'
 			TBLENCWWWCOMP_.freeze
 		end
-		return str.to_s.gsub( /[^*\-.0-9A-Z_a-z]/ ) {|*| TBLENCWWWCOMP_[$1] }
+		return str.to_s.gsub( /([^*\-.0-9A-Z_a-z])/ ) {|*| TBLENCWWWCOMP_[$1] }
 	end
 
 	# Decode given +str+ of URL-encoded form data.
 			TBLDECWWWCOMP_['+'] = ' '
 			TBLDECWWWCOMP_.freeze
 		end
-		raise ArgumentError, "invalid %-encoding (#{str})" unless /\A(?:%\h\h|[^%]+)*\z/ =~ str
-		return str.gsub( /\+|%\h\h/ ) {|*| TBLDECWWWCOMP_[$1] }
+		raise ArgumentError, "invalid %-encoding (#{str.dump})" unless /\A(?:%[[:xdigit:]]{2}|[^%]+)*\z/ =~ str
+		return str.gsub( /(\+|%[[:xdigit:]]{2})/ ) {|*| TBLDECWWWCOMP_[$1] }
 	end
 
 	# Generate URL-encoded form data from given +enum+.
 		str
 	end
 
-	WFKV_ = '(?:%\h\h|[^%#=;&])' # :nodoc:
+	WFKV_ = '(?:%[[:xdigit:]]{2}|[^%#=;&])' # :nodoc:
 
 	# Decode URL-encoded form data from given +str+.
 	#
 		end
 		ary = []
 		$&.scan(/([^=;&]+)=([^;&]*)/) do
-			ary << [decode_www_form_component($1, enc), decode_www_form_component($2, enc)]
+			ary << [decode_www_form_component($1), decode_www_form_component($2)]
 		end
 		ary
 	end

File spec/axis/camera_spec.rb

 			end
 
 			it "can fetch the video status of the first video source" do
-				@camera.video_status.should be_true()
+				pending "access to a test camera on which this is actually implemented" do
+					@camera.video_status.should be_true()
+				end
 			end
 
 		end

File spec/axis/monkeypatches_spec.rb

+#!/usr/bin/env rspec -cfd -b
+# encoding: utf-8
+
+BEGIN {
+	require 'pathname'
+	basedir = Pathname( __FILE__ ).dirname.parent.parent
+	libdir = basedir + 'lib'
+
+	$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
+	$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
+}
+
+require 'yaml'
+require 'stringio'
+
+require 'rspec'
+
+require 'spec/lib/helpers'
+require 'axis/camera'
+
+describe "URI 1.9.x compatibility monkeypatches", :ruby_1_8_only => true do
+
+	before( :all ) do
+		setup_logging( :fatal )
+	end
+
+	after( :all ) do
+		reset_logging()
+	end
+
+
+	it "adds an ::encode_www_form_component method to URI" do
+		URI.encode_www_form_component( "http://monkeycall.net/" ).
+			should == "http%3A%2F%2Fmonkeycall.net%2F"
+	end
+
+	it "adds a ::decode_www_form_component method to URI" do
+		URI.decode_www_form_component( "http%3A%2F%2Fmonkeycall.net%2F" ).
+			should == "http://monkeycall.net/"
+	end
+
+	it "adds an ::encode_www_form method to URI" do
+		URI.encode_www_form([ ['a', '1'], ['a', '2'], ['b', '3'] ]).
+			should == "a=1&a=2&b=3"
+	end
+
+	it "adds a ::decode_www_form method to URI" do
+		URI.decode_www_form( "a=1&a=2&b=3" ).
+			should == [ ['a', '1'], ['a', '2'], ['b', '3'] ]
+	end
+
+end
+

File spec/lib/helpers.rb

 
 	c.filter_run_excluding( :ruby_1_9_only => true ) if
 		Axis::SpecHelpers.vvec( RUBY_VERSION ) < Axis::SpecHelpers.vvec('1.9.0')
+	c.filter_run_excluding( :ruby_1_8_only => true ) if
+		Axis::SpecHelpers.vvec( RUBY_VERSION ) >= Axis::SpecHelpers.vvec('1.9.0')
 	c.filter_run_excluding( :config_exists => true ) unless
 		TEST_CONFIG_FILE.exist?
 end