From 6bba1e6aa2b75d2896f5896734273c13a3306478 Mon Sep 17 00:00:00 2001 From: Charles Duffy Date: Fri, 14 Jan 2011 13:53:45 -0600 Subject: [PATCH] reformat into a Hoe-based Gem --- .autotest | 23 +++++ .gitignore | 1 + ChangeLog | 65 ------------- History.txt | 51 +++++++++++ Makefile | 2 - Manifest.txt | 6 ++ README | 78 ---------------- README.txt | 113 +++++++++++++++++++++++ Rakefile | 10 ++ install.rb | 116 ------------------------ escape.rb => lib/escape.rb | 2 + test/{test-escape.rb => test_escape.rb} | 0 12 files changed, 206 insertions(+), 261 deletions(-) create mode 100644 .autotest create mode 100644 .gitignore delete mode 100644 ChangeLog create mode 100644 History.txt delete mode 100644 Makefile create mode 100644 Manifest.txt delete mode 100644 README create mode 100644 README.txt create mode 100644 Rakefile delete mode 100644 install.rb rename escape.rb => lib/escape.rb (99%) rename test/{test-escape.rb => test_escape.rb} (100%) diff --git a/.autotest b/.autotest new file mode 100644 index 0000000..ef753ad --- /dev/null +++ b/.autotest @@ -0,0 +1,23 @@ +# -*- ruby -*- + +require 'autotest/restart' + +# Autotest.add_hook :initialize do |at| +# at.extra_files << "../some/external/dependency.rb" +# +# at.libs << ":../some/external" +# +# at.add_exception 'vendor' +# +# at.add_mapping(/dependency.rb/) do |f, _| +# at.files_matching(/test_.*rb$/) +# end +# +# %w(TestA TestB).each do |klass| +# at.extra_class_map[klass] = "test/test_misc.rb" +# end +# end + +# Autotest.add_hook :run_command do |at| +# system "rake build" +# end diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5fff1d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +pkg diff --git a/ChangeLog b/ChangeLog deleted file mode 100644 index a43436a..0000000 --- a/ChangeLog +++ /dev/null @@ -1,65 +0,0 @@ -2009-10-04 Tanaka Akira - - * escape.rb (Escape.percent_encoding): remove duplicates in regex - character range to avoid a warning. - -2007-06-03 Tanaka Akira - - * escape.rb (Escape::MIMEParameter): new class. - (Escape.mime_token?): new method. - (Escape.rfc2822_quoted_string): ditto. - (Escape.mime_parameter_value): ditto. - (Escape.mime_parameter): ditto. - (Escape.http_token?): ditto. - (Escape.http_quoted_string): ditto. - (Escape.http_parameter_value): ditto. - (Escape.http_parameter): ditto. - (Escape.http_params_with_sep): ditto. - (Escape.http_params_with_pre): ditto. - -2007-03-05 Tanaka Akira - - * escape.rb (Escape::StringWrapper#escaped_string): New method. - -2007-03-03 Tanaka Akira - - * escape.rb: Escape.uri_path accepts an array of strings. - - * escape.rb: Escape::PercentEncoded#split_html_form implemented. - - * escape.rb: Escape.percent_encoding implemented. - -2007-02-28 Tanaka Akira - - * version 0.2 released. - -2007-02-28 Tanaka Akira - - * escape.rb: Escape::HTMLAttrValue defined. - Escape.html_attr_value returns it. - -2007-02-27 Tanaka Akira - - * escape.rb: make StringWrapper into class. - Escape::ShellEscaped, Escape::HTMLEscaped and Escape::PercentEncoded - inherit it. - -2007-02-26 Tanaka Akira - - * escape.rb: Escape::ShellEscaped defined. - Escape.shell_command and Escape.shell_single_word returns - Escape::ShellEscaped object instead of a string. - - * escape.rb: Escape::HTMLEscaped defined. - Escape.html_text and Escape.html_attr_value returns - Escape::HTMLEscaped object instead of a string. - - * escape.rb: Escape::PercentEncoded defined. - Escape.uri_segment, Escape.uri_path and Escape.html_form returns - Escape::PercentEncoded object instead of a string. - - * escape.rb: rename Escape.html_attr to Escape.html_attr_value. - -2007-01-05 Tanaka Akira - - * version 0.1 released. diff --git a/History.txt b/History.txt new file mode 100644 index 0000000..d642d54 --- /dev/null +++ b/History.txt @@ -0,0 +1,51 @@ +=== Unreleased + +* escape.rb (Escape.percent_encoding): remove duplicates in regex + character range to avoid a warning. + +* escape.rb (Escape::MIMEParameter): new class. + (Escape.mime_token?): new method. + (Escape.rfc2822_quoted_string): ditto. + (Escape.mime_parameter_value): ditto. + (Escape.mime_parameter): ditto. + (Escape.http_token?): ditto. + (Escape.http_quoted_string): ditto. + (Escape.http_parameter_value): ditto. + (Escape.http_parameter): ditto. + (Escape.http_params_with_sep): ditto. + (Escape.http_params_with_pre): ditto. + +* escape.rb (Escape::StringWrapper#escaped_string): New method. + +* escape.rb: Escape.uri_path accepts an array of strings. + +* escape.rb: Escape::PercentEncoded#split_html_form implemented. + +* escape.rb: Escape.percent_encoding implemented. + +=== 0.2 / 2007-02-28 + +* escape.rb: Escape::HTMLAttrValue defined. + Escape.html_attr_value returns it. + +* escape.rb: make StringWrapper into class. + Escape::ShellEscaped, Escape::HTMLEscaped and Escape::PercentEncoded + inherit it. + +* escape.rb: Escape::ShellEscaped defined. + Escape.shell_command and Escape.shell_single_word returns + Escape::ShellEscaped object instead of a string. + +* escape.rb: Escape::HTMLEscaped defined. + Escape.html_text and Escape.html_attr_value returns + Escape::HTMLEscaped object instead of a string. + +* escape.rb: Escape::PercentEncoded defined. + Escape.uri_segment, Escape.uri_path and Escape.html_form returns + Escape::PercentEncoded object instead of a string. + +* escape.rb: rename Escape.html_attr to Escape.html_attr_value. + +=== 0.1 / 2007-01-05 + +* Initial release diff --git a/Makefile b/Makefile deleted file mode 100644 index bd27903..0000000 --- a/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -rdoc: - rdoc --op rdoc escape.rb diff --git a/Manifest.txt b/Manifest.txt new file mode 100644 index 0000000..350a95f --- /dev/null +++ b/Manifest.txt @@ -0,0 +1,6 @@ +.autotest +Manifest.txt +README.txt +Rakefile +lib/escape.rb +test/test_escape.rb diff --git a/README b/README deleted file mode 100644 index 86c9adb..0000000 --- a/README +++ /dev/null @@ -1,78 +0,0 @@ -= escape - HTML/URI/shell escaping utilities - -escape library provides several HTML/URI/shell escaping functions. - -== Author - -Tanaka Akira - -== Home Page - -http://www.a-k-r.org/escape/ - -== Feature - -* several escaping/composing functions - * HTML text - * HTML attribute value - * HTML form (x-www-form-urlencoded) - * URI path - * shell command line -* dedicated classes for escaped strings -* escape and compose strongly related strings at once - -== Usage - - require 'escape' - - Escape.shell_command(["echo", "*"]) #=> # - Escape.uri_path("a?b/c?d/e?f") #=> # - Escape.html_form([["a","b"], ["c","d"]]) #=> # - Escape.html_form({"a"=>"b", "c"=>"d"}) #=> # - Escape.html_text("a & b < c > d") #=> # - Escape.html_attr_value("ab&<>\"c") #=> # - -== Requirements - -* ruby : http://www.ruby-lang.org/ - -== Download - -* latest release: http://www.a-k-r.org/escape/escape-0.2.tar.gz - -* development version: http://github.com/akr/escape - -== Install - - % ruby install.rb - -== Reference Manual - -See rdoc/classes/Escape.html or -http://www.a-k-r.org/escape/rdoc/classes/Escape.html - -== License - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -(1) Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. -(2) Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. -(3) The name of the author may not be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO -EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT -OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY -OF SUCH DAMAGE. - -(The modified BSD licence) diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..324c8bc --- /dev/null +++ b/README.txt @@ -0,0 +1,113 @@ += escape - HTML/URI/shell escaping utilities + +* http://www.a-k-r.org/escape/ + +== AUTHOR: + +Tanaka Akira + +== DESCRIPTION: + +escape library provides several HTML/URI/shell escaping functions. + +This library's shell escaping is more effective than that provided by the Ruby +standard library. + +== FEATURES/PROBLEMS: + +* several escaping/composing functions + * HTML text + * HTML attribute value + * HTML form (x-www-form-urlencoded) + * URI path + * shell command line +* dedicated classes for escaped strings +* escape and compose strongly related strings at once + +== DEVELOPERS: + +After checking out the source, run: + + $ rake newb + +This task will install any missing dependencies, run the tests/specs, +and generate the RDoc. + +== FEATURES: + +* several escaping/composing functions + * HTML text + * HTML attribute value + * HTML form (x-www-form-urlencoded) + * URI path + * shell command line +* dedicated classes for escaped strings +* escape and compose strongly related strings at once + +== SYNOPSIS: + + require 'rubygems' + require 'escape' + + Escape.shell_command(["echo", "*"]) #=> # + Escape.uri_path("a?b/c?d/e?f") #=> # + Escape.html_form([["a","b"], ["c","d"]]) #=> # + Escape.html_form({"a"=>"b", "c"=>"d"}) #=> # + Escape.html_text("a & b < c > d") #=> # + Escape.html_attr_value("ab&<>\"c") #=> # + +== REQUIREMENTS: + +* ruby : http://www.ruby-lang.org/ + +== DOWNLOAD: + +* latest release: (()) + +* development version on github: + + % git clone https://github.com/akr/escape + +== INSTALL: + +* rake install_gem + +== DOCUMENTATION: + +See rdoc/classes/Escape.html or +(()) + +== DEVELOPERS: + +After checking out the source, run: + + $ rake newb + +This task will install any missing dependencies, run the tests/specs, +and generate the RDoc. + +== LICENSE: + +The modified BSD licence + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + OF SUCH DAMAGE. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..a8085a0 --- /dev/null +++ b/Rakefile @@ -0,0 +1,10 @@ +# -*- ruby -*- + +require 'rubygems' +require 'hoe' + +Hoe.spec 'escape' do + developer('Tanaka Akira', 'akr@fsij.org') +end + +# vim: syntax=ruby diff --git a/install.rb b/install.rb deleted file mode 100644 index 1a7afef..0000000 --- a/install.rb +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env ruby - -# usage: ruby install.rb [-n] [--destdir=DESTDIR] [--vendor] -# options: -# -n : don't install -# --destdir=DESTDIR -# --vendor -# -# Author: Tanaka Akira - -require 'optparse' -require 'fileutils' - -def target_directory(vendor) - pat = vendor ? %r{/vendor_ruby/[\d.]+\z} : %r{/site_ruby/[\d.]+\z} - $:.each {|loc| - if pat =~ loc - return loc - end - } - raise "could not find target install directory" -end - -CVS_FILES = {} -def cvs_files(dir) - return CVS_FILES[dir] if CVS_FILES.include? dir - if File.directory? "#{dir}/CVS" - result = {} - File.foreach("#{dir}/CVS/Entries") {|line| - case line - when %r{\A/([^/]+)/} then result[$1] = true - when %r{\AD/([^/]+)/} then result[$1] = true - end - } - else - result = nil - end - CVS_FILES[dir] = result - result -end - -def each_target(&block) - target_set = {} - cvs = cvs_files('.') - Dir.glob("*.rb") {|filename| - next if /\Atest-/ =~ filename - next if /\Ainstall/ =~ filename - next if cvs && !cvs.include?(filename) - target_set[filename] = true - yield filename - each_require(filename, target_set, &block) - } -end - -def each_require(file, target_set, &block) - File.foreach(file) {|line| - next if /\A\s*require\s+['"]([^'"]+)['"]/ !~ line - feature = $1 - filename = "#{feature}.rb" - next if target_set.include? filename - next if !File.exist?(filename) - target_set[filename] = true - yield filename - each_require(filename, target_set, &block) - } -end - -def collect_target - result = [] - each_target {|filename| result << filename } - result.sort! - result -end - -def install_file(src, dst) - ignore_exc(Errno::ENOENT) { return if FileUtils.compare_file src, dst } - # check shadow - ignore_exc(Errno::ENOENT) { File.unlink dst } - FileUtils.mkdir_p(File.dirname(dst), :mode=>0755) - FileUtils.cp(src, dst, :verbose => true) - File.chmod(0644, dst) -end - -def ignore_exc(exc) - begin - yield - rescue exc - end -end - -$opt_n = false -$opt_destdir = "" -$opt_vendor = false -ARGV.options {|q| - q.banner = 'ruby install.rb [opts]' - q.def_option('--help', 'show this message') {puts q; exit(0)} - q.def_option('-n', "don't install") { $opt_n = true } - q.def_option('--destdir=DESTDIR', "specify DESTDIR") {|destdir| $opt_destdir = destdir } - q.def_option('--vendor', 'install to vendor directory') { $opt_vendor = true } - q.parse! -} - -if $opt_n - dir = target_directory($opt_vendor) - collect_target.each {|filename| - puts "-> #{$opt_destdir}#{dir}/#{filename}" - } - exit -else - File.umask 022 - dir = target_directory($opt_vendor) - collect_target.each {|filename| - install_file filename, "#{$opt_destdir}#{dir}/#{filename}" - } -end - diff --git a/escape.rb b/lib/escape.rb similarity index 99% rename from escape.rb rename to lib/escape.rb index 8502dab..db9f46e 100644 --- a/escape.rb +++ b/lib/escape.rb @@ -30,6 +30,8 @@ # * shell command # * MIME parameter module Escape + VERSION = '0.2' + module_function class StringWrapper diff --git a/test/test-escape.rb b/test/test_escape.rb similarity index 100% rename from test/test-escape.rb rename to test/test_escape.rb