escape-0.2/0000755000000000000000000000000010571247750011321 5ustar rootrootescape-0.2/test/0000755000000000000000000000000010571247750012300 5ustar rootrootescape-0.2/test/test-escape.rb0000644000000000000000000000534210571164604015042 0ustar rootrootrequire 'test/unit' require 'escape' class TestEscapeStringWrapper < Test::Unit::TestCase def test_eq assert(Escape::PercentEncoded.new("foo") == Escape::PercentEncoded.new("foo")) assert(Escape::PercentEncoded.new("foo") != Escape::PercentEncoded.new("bar")) assert(Escape::ShellEscaped.new("a") != Escape::PercentEncoded.new("a")) end def test_hash v1 = Escape::PercentEncoded.new("foo") v2 = Escape::PercentEncoded.new("foo") h = {} h[v1] = 1 h[v2] = 2 assert_equal(1, h.size) assert_equal(2, h[v1]) end def test_new_dup s = "a" o = Escape::PercentEncoded.new(s) assert_not_equal(s.object_id, o.instance_variable_get(:@str).object_id) o = Escape::PercentEncoded.new_no_dup(s) assert_equal(s.object_id, o.instance_variable_get(:@str).object_id) end end class TestEscapeShellEscaped < Test::Unit::TestCase def assert_equal_se(str, tst) assert_equal(Escape::ShellEscaped.new(str), tst) end def test_shell_command assert_equal_se("com arg", Escape.shell_command(%w[com arg])) assert_equal_se("ls /", Escape.shell_command(%w[ls /])) assert_equal_se("echo '*'", Escape.shell_command(%w[echo *])) end def test_shell_single_word assert_equal_se("''", Escape.shell_single_word('')) assert_equal_se("foo", Escape.shell_single_word('foo')) assert_equal_se("'*'", Escape.shell_single_word('*')) end end class TestEscapePercentEncoded < Test::Unit::TestCase def assert_equal_pe(str, tst) assert_equal(Escape::PercentEncoded.new(str), tst) end def test_uri_segment assert_kind_of(Escape::PercentEncoded, Escape.uri_segment("foo")) assert_equal_pe("a%2Fb", Escape.uri_segment("a/b")) end def test_uri_path assert_kind_of(Escape::PercentEncoded, Escape.uri_path("foo")) assert_equal_pe("a/b/c", Escape.uri_path("a/b/c")) assert_equal_pe("a%3Fb/c%3Fd/e%3Ff", Escape.uri_path("a?b/c?d/e?f")) end def test_html_form assert_kind_of(Escape::PercentEncoded, Escape.html_form([["foo","bar"]])) assert_equal_pe("a=b&c=d", Escape.html_form([["a","b"], ["c","d"]])) assert_equal_pe("a=b;c=d", Escape.html_form([["a","b"], ["c","d"]], ';')) assert_equal_pe("k=1&k=2", Escape.html_form([["k","1"], ["k","2"]])) assert_equal_pe("k%3D=%26%3B%3D", Escape.html_form([["k=","&;="]])) end end class TestEscapeHTML < Test::Unit::TestCase def assert_equal_he(str, tst) assert_equal(Escape::HTMLEscaped.new(str), tst) end def assert_equal_hav(str, tst) assert_equal(Escape::HTMLAttrValue.new(str), tst) end def test_html_text assert_equal_he('a&<>"', Escape.html_text('a&<>"')) end def test_html_attr_value assert_equal_hav('"a&<>""', Escape.html_attr_value('a&<>"')) end end escape-0.2/misc/0000755000000000000000000000000010571247750012254 5ustar rootrootescape-0.2/misc/README.erb0000644000000000000000000000551210571247360013703 0ustar rootroot= escape - HTML/URI/shell escaping utilities <% def version File.read("VERSION").chomp end %> escape library provides several HTML/URI/shell escaping functions. == Author Tanaka Akira == Home Page (()) == 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: ((.tar.gz|URL:escape-<%=version%>.tar.gz>)) * development version in Subversion repository: % svn co svn://svn@svn.a-k-r.org/akr/escape/trunk escape == Install % ruby install.rb == Reference Manual See rdoc/classes/Escape.html or (()) == 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. escape-0.2/rdoc/0000755000000000000000000000000010571247750012250 5ustar rootrootescape-0.2/rdoc/rdoc-style.css0000644000000000000000000001033210571247750015046 0ustar rootroot body { font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 90%; margin: 0; margin-left: 40px; padding: 0; background: white; } h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; } h1 { font-size: 150%; } h2,h3,h4 { margin-top: 1em; } a { background: #eef; color: #039; text-decoration: none; } a:hover { background: #039; color: #eef; } /* Override the base stylesheet's Anchor inside a table cell */ td > a { background: transparent; color: #039; text-decoration: none; } /* and inside a section title */ .section-title > a { background: transparent; color: #eee; text-decoration: none; } /* === Structural elements =================================== */ div#index { margin: 0; margin-left: -40px; padding: 0; font-size: 90%; } div#index a { margin-left: 0.7em; } div#index .section-bar { margin-left: 0px; padding-left: 0.7em; background: #ccc; font-size: small; } div#classHeader, div#fileHeader { width: auto; color: white; padding: 0.5em 1.5em 0.5em 1.5em; margin: 0; margin-left: -40px; border-bottom: 3px solid #006; } div#classHeader a, div#fileHeader a { background: inherit; color: white; } div#classHeader td, div#fileHeader td { background: inherit; color: white; } div#fileHeader { background: #057; } div#classHeader { background: #048; } .class-name-in-header { font-size: 180%; font-weight: bold; } div#bodyContent { padding: 0 1.5em 0 1.5em; } div#description { padding: 0.5em 1.5em; background: #efefef; border: 1px dotted #999; } div#description h1,h2,h3,h4,h5,h6 { color: #125;; background: transparent; } div#validator-badges { text-align: center; } div#validator-badges img { border: 0; } div#copyright { color: #333; background: #efefef; font: 0.75em sans-serif; margin-top: 5em; margin-bottom: 0; padding: 0.5em 2em; } /* === Classes =================================== */ table.header-table { color: white; font-size: small; } .type-note { font-size: small; color: #DEDEDE; } .xxsection-bar { background: #eee; color: #333; padding: 3px; } .section-bar { color: #333; border-bottom: 1px solid #999; margin-left: -20px; } .section-title { background: #79a; color: #eee; padding: 3px; margin-top: 2em; margin-left: -30px; border: 1px solid #999; } .top-aligned-row { vertical-align: top } .bottom-aligned-row { vertical-align: bottom } /* --- Context section classes ----------------------- */ .context-row { } .context-item-name { font-family: monospace; font-weight: bold; color: black; } .context-item-value { font-size: small; color: #448; } .context-item-desc { color: #333; padding-left: 2em; } /* --- Method classes -------------------------- */ .method-detail { background: #efefef; padding: 0; margin-top: 0.5em; margin-bottom: 1em; border: 1px dotted #ccc; } .method-heading { color: black; background: #ccc; border-bottom: 1px solid #666; padding: 0.2em 0.5em 0 0.5em; } .method-signature { color: black; background: inherit; } .method-name { font-weight: bold; } .method-args { font-style: italic; } .method-description { padding: 0 0.5em 0 0.5em; } /* --- Source code sections -------------------- */ a.source-toggle { font-size: 90%; } div.method-source-code { background: #262626; color: #ffdead; margin: 1em; padding: 0.5em; border: 1px dashed #999; overflow: hidden; } div.method-source-code pre { color: #ffdead; overflow: hidden; } /* --- Ruby keyword styles --------------------- */ .standalone-code { background: #221111; color: #ffdead; overflow: hidden; } .ruby-constant { color: #7fffd4; background: transparent; } .ruby-keyword { color: #00ffff; background: transparent; } .ruby-ivar { color: #eedd82; background: transparent; } .ruby-operator { color: #00ffee; background: transparent; } .ruby-identifier { color: #ffdead; background: transparent; } .ruby-node { color: #ffa07a; background: transparent; } .ruby-comment { color: #b22222; font-weight: bold; background: transparent; } .ruby-regexp { color: #ffa07a; background: transparent; } .ruby-value { color: #7fffd4; background: transparent; }escape-0.2/rdoc/files/0000755000000000000000000000000010571247750013352 5ustar rootrootescape-0.2/rdoc/files/install_rb.src/0000755000000000000000000000000010571247750016271 5ustar rootrootescape-0.2/rdoc/files/install_rb.src/M000001.html0000644000000000000000000000245710571247750020024 0ustar rootroot target_directory (install.rb)
# File install.rb, line 12
def target_directory
  $:.each {|loc|
    if %r{/site_ruby/[\d.]+\z} =~ loc
      return loc
    end
  }
  raise "could not find target install directory"
end
escape-0.2/rdoc/files/install_rb.src/M000002.html0000644000000000000000000000477310571247750020030 0ustar rootroot cvs_files (install.rb)
# File install.rb, line 22
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
escape-0.2/rdoc/files/install_rb.src/M000003.html0000644000000000000000000000461210571247750020021 0ustar rootroot each_target (install.rb)
# File install.rb, line 39
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
escape-0.2/rdoc/files/install_rb.src/M000004.html0000644000000000000000000000467210571247750020030 0ustar rootroot each_require (install.rb)
# File install.rb, line 52
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
escape-0.2/rdoc/files/install_rb.src/M000005.html0000644000000000000000000000221110571247750020014 0ustar rootroot collect_target (install.rb)
# File install.rb, line 65
def collect_target
  result = []
  each_target {|filename| result << filename }
  result.sort!
  result
end
escape-0.2/rdoc/files/install_rb.src/M000006.html0000644000000000000000000000445110571247750020025 0ustar rootroot install_file (install.rb)
# File install.rb, line 72
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
escape-0.2/rdoc/files/install_rb.src/M000007.html0000644000000000000000000000163510571247750020027 0ustar rootroot ignore_exc (install.rb)
# File install.rb, line 81
def ignore_exc(exc)
  begin
    yield
  rescue exc
  end
end
escape-0.2/rdoc/files/test/0000755000000000000000000000000010571247750014331 5ustar rootrootescape-0.2/rdoc/files/test/test-escape_rb.html0000644000000000000000000000425410571247750020124 0ustar rootroot File: test-escape.rb

test-escape.rb

Path: test/test-escape.rb
Last Update: 2007-02-28 11:31:32 +0900

Required files

test/unit   escape  
escape-0.2/rdoc/files/escape_rb.html0000644000000000000000000000672510571247750016175 0ustar rootroot File: escape.rb

escape.rb

Path: escape.rb
Last Update: 2007-02-28 18:21:33 +0900

escape.rb - escape/unescape library for several formats

Copyright (C) 2006,2007 Tanaka Akira <akr@fsij.org>

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.

escape-0.2/rdoc/files/install_rb.html0000644000000000000000000001520510571247750016374 0ustar rootroot File: install.rb

install.rb

Path: install.rb
Last Update: 2007-01-04 03:24:56 +0900

usage: ruby install.rb [-n] options:

 -n : don't install

Author: Tanaka Akira <akr@m17n.org>

Required files

optparse   fileutils  
escape-0.2/rdoc/classes/0000755000000000000000000000000010571247750013705 5ustar rootrootescape-0.2/rdoc/classes/TestEscapeHTML.src/0000755000000000000000000000000010571247750017220 5ustar rootrootescape-0.2/rdoc/classes/TestEscapeHTML.src/M000008.html0000644000000000000000000000206510571247750020755 0ustar rootroot assert_equal_he (TestEscapeHTML)
# File test/test-escape.rb, line 75
  def assert_equal_he(str, tst)
    assert_equal(Escape::HTMLEscaped.new(str), tst)
  end
escape-0.2/rdoc/classes/TestEscapeHTML.src/M000009.html0000644000000000000000000000207110571247750020753 0ustar rootroot assert_equal_hav (TestEscapeHTML)
# File test/test-escape.rb, line 79
  def assert_equal_hav(str, tst)
    assert_equal(Escape::HTMLAttrValue.new(str), tst)
  end
escape-0.2/rdoc/classes/TestEscapeHTML.src/M000010.html0000644000000000000000000000170510571247750020746 0ustar rootroot test_html_text (TestEscapeHTML)
# File test/test-escape.rb, line 83
  def test_html_text
    assert_equal_he('a&amp;&lt;&gt;"', Escape.html_text('a&<>"'))
  end
escape-0.2/rdoc/classes/TestEscapeHTML.src/M000011.html0000644000000000000000000000175010571247750020747 0ustar rootroot test_html_attr_value (TestEscapeHTML)
# File test/test-escape.rb, line 87
  def test_html_attr_value
    assert_equal_hav('"a&amp;&lt;&gt;&quot;"', Escape.html_attr_value('a&<>"'))
  end
escape-0.2/rdoc/classes/TestEscapePercentEncoded.src/0000755000000000000000000000000010571247750021336 5ustar rootrootescape-0.2/rdoc/classes/TestEscapePercentEncoded.src/M000012.html0000644000000000000000000000210210571247750023056 0ustar rootroot assert_equal_pe (TestEscapePercentEncoded)
# File test/test-escape.rb, line 50
  def assert_equal_pe(str, tst)
    assert_equal(Escape::PercentEncoded.new(str), tst)
  end
escape-0.2/rdoc/classes/TestEscapePercentEncoded.src/M000013.html0000644000000000000000000000240710571247750023067 0ustar rootroot test_uri_segment (TestEscapePercentEncoded)
# File test/test-escape.rb, line 54
  def test_uri_segment
    assert_kind_of(Escape::PercentEncoded, Escape.uri_segment("foo"))
    assert_equal_pe("a%2Fb", Escape.uri_segment("a/b"))
  end
escape-0.2/rdoc/classes/TestEscapePercentEncoded.src/M000014.html0000644000000000000000000000301710571247750023066 0ustar rootroot test_uri_path (TestEscapePercentEncoded)
# File test/test-escape.rb, line 59
  def test_uri_path
    assert_kind_of(Escape::PercentEncoded, Escape.uri_path("foo"))
    assert_equal_pe("a/b/c", Escape.uri_path("a/b/c"))
    assert_equal_pe("a%3Fb/c%3Fd/e%3Ff", Escape.uri_path("a?b/c?d/e?f"))
  end
escape-0.2/rdoc/classes/TestEscapePercentEncoded.src/M000015.html0000644000000000000000000000520010571247750023063 0ustar rootroot test_html_form (TestEscapePercentEncoded)
# File test/test-escape.rb, line 65
  def test_html_form
    assert_kind_of(Escape::PercentEncoded, Escape.html_form([["foo","bar"]]))
    assert_equal_pe("a=b&c=d", Escape.html_form([["a","b"], ["c","d"]]))
    assert_equal_pe("a=b;c=d", Escape.html_form([["a","b"], ["c","d"]], ';'))
    assert_equal_pe("k=1&k=2", Escape.html_form([["k","1"], ["k","2"]]))
    assert_equal_pe("k%3D=%26%3B%3D", Escape.html_form([["k=","&;="]]))
  end
escape-0.2/rdoc/classes/TestEscapeShellEscaped.src/0000755000000000000000000000000010571247750021010 5ustar rootrootescape-0.2/rdoc/classes/TestEscapeShellEscaped.src/M000016.html0000644000000000000000000000207610571247750022546 0ustar rootroot assert_equal_se (TestEscapeShellEscaped)
# File test/test-escape.rb, line 31
  def assert_equal_se(str, tst)
    assert_equal(Escape::ShellEscaped.new(str), tst)
  end
escape-0.2/rdoc/classes/TestEscapeShellEscaped.src/M000017.html0000644000000000000000000000265410571247750022551 0ustar rootroot test_shell_command (TestEscapeShellEscaped)
# File test/test-escape.rb, line 35
  def test_shell_command
    assert_equal_se("com arg", Escape.shell_command(%w[com arg]))
    assert_equal_se("ls /", Escape.shell_command(%w[ls /]))
    assert_equal_se("echo '*'", Escape.shell_command(%w[echo *]))
  end
escape-0.2/rdoc/classes/TestEscapeShellEscaped.src/M000018.html0000644000000000000000000000266110571247750022550 0ustar rootroot test_shell_single_word (TestEscapeShellEscaped)
# File test/test-escape.rb, line 41
  def test_shell_single_word
    assert_equal_se("''", Escape.shell_single_word(''))
    assert_equal_se("foo", Escape.shell_single_word('foo'))
    assert_equal_se("'*'", Escape.shell_single_word('*'))
  end
escape-0.2/rdoc/classes/TestEscapeStringWrapper.src/0000755000000000000000000000000010571247750021263 5ustar rootrootescape-0.2/rdoc/classes/TestEscapeStringWrapper.src/M000019.html0000644000000000000000000000433310571247750023022 0ustar rootroot test_eq (TestEscapeStringWrapper)
# File test/test-escape.rb, line 5
  def test_eq
    assert(Escape::PercentEncoded.new("foo") == Escape::PercentEncoded.new("foo"))
    assert(Escape::PercentEncoded.new("foo") != Escape::PercentEncoded.new("bar"))
    assert(Escape::ShellEscaped.new("a") != Escape::PercentEncoded.new("a"))
  end
escape-0.2/rdoc/classes/TestEscapeStringWrapper.src/M000020.html0000644000000000000000000000347210571247750023015 0ustar rootroot test_hash (TestEscapeStringWrapper)
# File test/test-escape.rb, line 11
  def test_hash
    v1 = Escape::PercentEncoded.new("foo")
    v2 = Escape::PercentEncoded.new("foo")
    h = {}
    h[v1] = 1
    h[v2] = 2
    assert_equal(1, h.size)
    assert_equal(2, h[v1])
  end
escape-0.2/rdoc/classes/TestEscapeStringWrapper.src/M000021.html0000644000000000000000000000365710571247750023023 0ustar rootroot test_new_dup (TestEscapeStringWrapper)
# File test/test-escape.rb, line 21
  def test_new_dup
    s = "a"
    o = Escape::PercentEncoded.new(s)
    assert_not_equal(s.object_id, o.instance_variable_get(:@str).object_id)
    o = Escape::PercentEncoded.new_no_dup(s)
    assert_equal(s.object_id, o.instance_variable_get(:@str).object_id)
  end
escape-0.2/rdoc/classes/Escape.src/0000755000000000000000000000000010571247750015673 5ustar rootrootescape-0.2/rdoc/classes/Escape.src/M000022.html0000644000000000000000000000240110571247750017416 0ustar rootroot shell_command (Escape)
# File escape.rb, line 86
  def shell_command(command)
    s = command.map {|word| shell_single_word(word) }.join(' ')
    ShellEscaped.new_no_dup(s)
  end
escape-0.2/rdoc/classes/Escape.src/M000023.html0000644000000000000000000000455110571247750017427 0ustar rootroot shell_single_word (Escape)
# File escape.rb, line 101
  def shell_single_word(str)
    if str.empty?
      ShellEscaped.new_no_dup("''")
    elsif %r{\A[0-9A-Za-z+,./:=@_-]+\z} =~ str
      ShellEscaped.new(str)
    else
      result = ''
      str.scan(/('+)|[^']+/) {
        if $1
          result << %q{\'} * $1.length
        else
          result << "'#{$&}'"
        end
      }
      ShellEscaped.new_no_dup(result)
    end
  end
escape-0.2/rdoc/classes/Escape.src/M000024.html0000644000000000000000000000347610571247750017435 0ustar rootroot uri_segment (Escape)
# File escape.rb, line 132
  def uri_segment(str)
    # pchar - pct-encoded = unreserved / sub-delims / ":" / "@"
    # unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
    # sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
    s = str.gsub(%r{[^A-Za-z0-9\-._~!$&'()*+,;=:@]}n) {
      '%' + $&.unpack("H2")[0].upcase
    }
    PercentEncoded.new_no_dup(s)
  end
escape-0.2/rdoc/classes/Escape.src/M000025.html0000644000000000000000000000213310571247750017423 0ustar rootroot uri_path (Escape)
# File escape.rb, line 157
  def uri_path(str)
    s = str.gsub(%r{[^/]+}n) { uri_segment($&) }
    PercentEncoded.new_no_dup(s)
  end
escape-0.2/rdoc/classes/Escape.src/M000026.html0000644000000000000000000001244410571247750017432 0ustar rootroot html_form (Escape)
# File escape.rb, line 209
  def html_form(pairs, sep='&')
    r = ''
    first = true
    pairs.each {|k, v|
      # query-chars - pct-encoded - x-www-form-urlencoded-delimiters =
      #   unreserved / "!" / "$" / "'" / "(" / ")" / "*" / "," / ":" / "@" / "/" / "?"
      # query-char - pct-encoded = unreserved / sub-delims / ":" / "@" / "/" / "?"
      # query-char = pchar / "/" / "?" = unreserved / pct-encoded / sub-delims / ":" / "@" / "/" / "?"
      # unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
      # sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
      # x-www-form-urlencoded-delimiters = "&" / "+" / ";" / "="
      r << sep if !first
      first = false
      k.each_byte {|byte|
        ch = byte.chr
        if %r{[^0-9A-Za-z\-\._~:/?@!\$'()*,]}n =~ ch
          r << "%" << ch.unpack("H2")[0].upcase
        else
          r << ch
        end
      }
      r << '='
      v.each_byte {|byte|
        ch = byte.chr
        if %r{[^0-9A-Za-z\-\._~:/?@!\$'()*,]}n =~ ch
          r << "%" << ch.unpack("H2")[0].upcase
        else
          r << ch
        end
      }
    }
    PercentEncoded.new_no_dup(r)
  end
escape-0.2/rdoc/classes/Escape.src/M000027.html0000644000000000000000000000232410571247750017427 0ustar rootroot html_text (Escape)
# File escape.rb, line 267
  def html_text(str)
    s = str.gsub(/[&<>]/) {|ch| HTML_TEXT_ESCAPE_HASH[ch] }
    HTMLEscaped.new_no_dup(s)
  end
escape-0.2/rdoc/classes/Escape.src/M000028.html0000644000000000000000000000261410571247750017432 0ustar rootroot html_attr_value (Escape)
# File escape.rb, line 298
  def html_attr_value(str)
    s = '"' + str.gsub(/[&<>"]/) {|ch| HTML_ATTR_ESCAPE_HASH[ch] } + '"'
    HTMLAttrValue.new_no_dup(s)
  end
escape-0.2/rdoc/classes/Escape/0000755000000000000000000000000010571247750015105 5ustar rootrootescape-0.2/rdoc/classes/Escape/StringWrapper.src/0000755000000000000000000000000010571247750020502 5ustar rootrootescape-0.2/rdoc/classes/Escape/StringWrapper.src/M000029.html0000644000000000000000000000152510571247750022242 0ustar rootroot new (Escape::StringWrapper)
# File escape.rb, line 37
      def new(str)
        new_no_dup(str.dup)
      end
escape-0.2/rdoc/classes/Escape/StringWrapper.src/M000030.html0000644000000000000000000000144210571247750022230 0ustar rootroot new (Escape::StringWrapper)
# File escape.rb, line 42
    def initialize(str)
      @str = str
    end
escape-0.2/rdoc/classes/Escape/StringWrapper.src/M000031.html0000644000000000000000000000136110571247750022231 0ustar rootroot to_s (Escape::StringWrapper)
# File escape.rb, line 46
    def to_s
      @str.dup
    end
escape-0.2/rdoc/classes/Escape/StringWrapper.src/M000032.html0000644000000000000000000000136610571247750022237 0ustar rootroot inspect (Escape::StringWrapper)
# File escape.rb, line 50
    def inspect
      "\#<#{self.class}: #{@str}>"
    end
escape-0.2/rdoc/classes/Escape/StringWrapper.src/M000033.html0000644000000000000000000000224510571247750022235 0ustar rootroot == (Escape::StringWrapper)
# File escape.rb, line 54
    def ==(other)
      other.class == self.class && @str == other.instance_variable_get(:@str)
    end
escape-0.2/rdoc/classes/Escape/StringWrapper.src/M000035.html0000644000000000000000000000136210571247750022236 0ustar rootroot hash (Escape::StringWrapper)
# File escape.rb, line 59
    def hash
      @str.hash
    end
escape-0.2/rdoc/classes/Escape/HTMLAttrValue.html0000644000000000000000000000451210571247750020371 0ustar rootroot Class: Escape::HTMLAttrValue
Class Escape::HTMLAttrValue
In: escape.rb
Parent: StringWrapper
escape-0.2/rdoc/classes/Escape/ShellEscaped.html0000644000000000000000000000451010571247750020327 0ustar rootroot Class: Escape::ShellEscaped
Class Escape::ShellEscaped
In: escape.rb
Parent: StringWrapper
escape-0.2/rdoc/classes/Escape/StringWrapper.html0000644000000000000000000001464510571247750020614 0ustar rootroot Class: Escape::StringWrapper
Class Escape::StringWrapper
In: escape.rb
Parent: Object

Methods

==   eql?   hash   inspect   new   new   to_s  

External Aliases

new -> new_no_dup

Public Class methods

Public Instance methods

eql?(other)

Alias for #==

escape-0.2/rdoc/classes/Escape/PercentEncoded.html0000644000000000000000000000451410571247750020661 0ustar rootroot Class: Escape::PercentEncoded
Class Escape::PercentEncoded
In: escape.rb
Parent: StringWrapper
escape-0.2/rdoc/classes/Escape/HTMLEscaped.html0000644000000000000000000000450610571247750020031 0ustar rootroot Class: Escape::HTMLEscaped
Class Escape::HTMLEscaped
In: escape.rb
Parent: StringWrapper
escape-0.2/rdoc/classes/TestEscapeHTML.html0000644000000000000000000001125510571247750017324 0ustar rootroot Class: TestEscapeHTML
Class TestEscapeHTML
In: test/test-escape.rb
Parent: Test::Unit::TestCase
escape-0.2/rdoc/classes/TestEscapePercentEncoded.html0000644000000000000000000001137310571247750021443 0ustar rootroot Class: TestEscapePercentEncoded
Class TestEscapePercentEncoded
In: test/test-escape.rb
Parent: Test::Unit::TestCase
escape-0.2/rdoc/classes/TestEscapeShellEscaped.html0000644000000000000000000001030510571247750021107 0ustar rootroot Class: TestEscapeShellEscaped
Class TestEscapeShellEscaped
In: test/test-escape.rb
Parent: Test::Unit::TestCase
escape-0.2/rdoc/classes/TestEscapeStringWrapper.html0000644000000000000000000001021710571247750021364 0ustar rootroot Class: TestEscapeStringWrapper
Class TestEscapeStringWrapper
In: test/test-escape.rb
Parent: Test::Unit::TestCase

Methods

escape-0.2/rdoc/classes/Escape.html0000644000000000000000000003171210571247750015777 0ustar rootroot Module: Escape
Module Escape
In: escape.rb

Escape module provides several escape functions.

  • URI
  • HTML
  • shell command

Public Instance methods

Escape.html_attr_value encodes a string as a double-quoted HTML attribute using character references. It returns an instance of HTMLAttrValue.

 Escape.html_attr_value("abc") #=> #<Escape::HTMLAttrValue: "abc">
 Escape.html_attr_value("a&b") #=> #<Escape::HTMLAttrValue: "a&amp;b">
 Escape.html_attr_value("ab&<>\"c") #=> #<Escape::HTMLAttrValue: "ab&amp;&lt;&gt;&quot;c">
 Escape.html_attr_value("a'c") #=> #<Escape::HTMLAttrValue: "a'c">

It escapes 4 characters:

  • ’&’ to ’&amp;’
  • ’<’ to ’&lt;’
  • ’>’ to ’&gt;’
  • ’"’ to ’&quot;’

Escape.html_form composes HTML form key-value pairs as a x-www-form-urlencoded encoded string. It returns an instance of PercentEncoded.

Escape.html_form takes an array of pair of strings or an hash from string to string.

 Escape.html_form([["a","b"], ["c","d"]]) #=> #<Escape::PercentEncoded: a=b&c=d>
 Escape.html_form({"a"=>"b", "c"=>"d"}) #=> #<Escape::PercentEncoded: a=b&c=d>

In the array form, it is possible to use same key more than once. (It is required for a HTML form which contains checkboxes and select element with multiple attribute.)

 Escape.html_form([["k","1"], ["k","2"]]) #=> #<Escape::PercentEncoded: k=1&k=2>

If the strings contains characters which must be escaped in x-www-form-urlencoded, they are escaped using %-encoding.

 Escape.html_form([["k=","&;="]]) #=> #<Escape::PercentEncoded: k%3D=%26%3B%3D>

The separator can be specified by the optional second argument.

 Escape.html_form([["a","b"], ["c","d"]], ";") #=> #<Escape::PercentEncoded: a=b;c=d>

See HTML 4.01 for details.

Escape.html_text escapes a string appropriate for HTML text using character references. It returns an instance of HTMLEscaped.

It escapes 3 characters:

  • ’&’ to ’&amp;’
  • ’<’ to ’&lt;’
  • ’>’ to ’&gt;’
 Escape.html_text("abc") #=> #<Escape::HTMLEscaped: abc>
 Escape.html_text("a & b < c > d") #=> #<Escape::HTMLEscaped: a &amp; b &lt; c &gt; d>

This function is not appropriate for escaping HTML element attribute because quotes are not escaped.

Escape.shell_command composes a sequence of words to a single shell command line. All shell meta characters are quoted and the words are concatenated with interleaving space. It returns an instance of ShellEscaped.

 Escape.shell_command(["ls", "/"]) #=> #<Escape::ShellEscaped: ls />
 Escape.shell_command(["echo", "*"]) #=> #<Escape::ShellEscaped: echo '*'>

Note that system(*command) and system(Escape.shell_command(command)) is roughly same. There are two exception as follows.

  • The first is that the later may invokes /bin/sh.
  • The second is an interpretation of an array with only one element: the element is parsed by the shell with the former but it is recognized as single word with the later. For example, system(*["echo foo"]) invokes echo command with an argument "foo". But system(Escape.shell_command(["echo foo"])) invokes "echo foo" command without arguments (and it probably fails).

Escape.shell_single_word quotes shell meta characters. It returns an instance of ShellEscaped.

The result string is always single shell word, even if the argument is "". Escape.shell_single_word("") returns #<Escape::ShellEscaped: ’’>.

 Escape.shell_single_word("") #=> #<Escape::ShellEscaped: ''>
 Escape.shell_single_word("foo") #=> #<Escape::ShellEscaped: foo>
 Escape.shell_single_word("*") #=> #<Escape::ShellEscaped: '*'>

Escape.uri_path escapes URI path using percent-encoding. The given path should be a sequence of (non-escaped) segments separated by "/". The segments cannot contains "/". It returns an instance of PercentEncoded.

 Escape.uri_path("a/b/c") #=> #<Escape::PercentEncoded: a/b/c>
 Escape.uri_path("a?b/c?d/e?f") #=> #<Escape::PercentEncoded: a%3Fb/c%3Fd/e%3Ff>

The path is the part after authority before query in URI, as follows.

  scheme://authority/path#fragment

See RFC 3986 for details of URI.

Note that this function is not appropriate to convert OS path to URI.

Escape.uri_segment escapes URI segment using percent-encoding. It returns an instance of PercentEncoded.

 Escape.uri_segment("a/b") #=> #<Escape::PercentEncoded: a%2Fb>

The segment is "/"-splitted element after authority before query in URI, as follows.

  scheme://authority/segment1/segment2/.../segmentN?query#fragment

See RFC 3986 for details of URI.

escape-0.2/rdoc/fr_file_index.html0000644000000000000000000000142010571247750015730 0ustar rootroot Files escape-0.2/rdoc/fr_class_index.html0000644000000000000000000000253410571247750016125 0ustar rootroot Classes escape-0.2/rdoc/fr_method_index.html0000644000000000000000000000735710571247750016310 0ustar rootroot Methods escape-0.2/rdoc/index.html0000644000000000000000000000136310571247750014250 0ustar rootroot RDoc Documentation escape-0.2/escape.rb0000644000000000000000000002440110571244635013106 0ustar rootroot# escape.rb - escape/unescape library for several formats # # Copyright (C) 2006,2007 Tanaka Akira # # 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. # Escape module provides several escape functions. # * URI # * HTML # * shell command module Escape module_function class StringWrapper class << self alias new_no_dup new def new(str) new_no_dup(str.dup) end end def initialize(str) @str = str end def to_s @str.dup end def inspect "\#<#{self.class}: #{@str}>" end def ==(other) other.class == self.class && @str == other.instance_variable_get(:@str) end alias eql? == def hash @str.hash end end class ShellEscaped < StringWrapper end # Escape.shell_command composes # a sequence of words to # a single shell command line. # All shell meta characters are quoted and # the words are concatenated with interleaving space. # It returns an instance of ShellEscaped. # # Escape.shell_command(["ls", "/"]) #=> # # Escape.shell_command(["echo", "*"]) #=> # # # Note that system(*command) and # system(Escape.shell_command(command)) is roughly same. # There are two exception as follows. # * The first is that the later may invokes /bin/sh. # * The second is an interpretation of an array with only one element: # the element is parsed by the shell with the former but # it is recognized as single word with the later. # For example, system(*["echo foo"]) invokes echo command with an argument "foo". # But system(Escape.shell_command(["echo foo"])) invokes "echo foo" command without arguments (and it probably fails). def shell_command(command) s = command.map {|word| shell_single_word(word) }.join(' ') ShellEscaped.new_no_dup(s) end # Escape.shell_single_word quotes shell meta characters. # It returns an instance of ShellEscaped. # # The result string is always single shell word, even if # the argument is "". # Escape.shell_single_word("") returns #. # # Escape.shell_single_word("") #=> # # Escape.shell_single_word("foo") #=> # # Escape.shell_single_word("*") #=> # def shell_single_word(str) if str.empty? ShellEscaped.new_no_dup("''") elsif %r{\A[0-9A-Za-z+,./:=@_-]+\z} =~ str ShellEscaped.new(str) else result = '' str.scan(/('+)|[^']+/) { if $1 result << %q{\'} * $1.length else result << "'#{$&}'" end } ShellEscaped.new_no_dup(result) end end class PercentEncoded < StringWrapper end # Escape.uri_segment escapes URI segment using percent-encoding. # It returns an instance of PercentEncoded. # # Escape.uri_segment("a/b") #=> # # # The segment is "/"-splitted element after authority before query in URI, as follows. # # scheme://authority/segment1/segment2/.../segmentN?query#fragment # # See RFC 3986 for details of URI. def uri_segment(str) # pchar - pct-encoded = unreserved / sub-delims / ":" / "@" # unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" # sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" s = str.gsub(%r{[^A-Za-z0-9\-._~!$&'()*+,;=:@]}n) { '%' + $&.unpack("H2")[0].upcase } PercentEncoded.new_no_dup(s) end # Escape.uri_path escapes URI path using percent-encoding. # The given path should be a sequence of (non-escaped) segments separated by "/". # The segments cannot contains "/". # It returns an instance of PercentEncoded. # # Escape.uri_path("a/b/c") #=> # # Escape.uri_path("a?b/c?d/e?f") #=> # # # The path is the part after authority before query in URI, as follows. # # scheme://authority/path#fragment # # See RFC 3986 for details of URI. # # Note that this function is not appropriate to convert OS path to URI. def uri_path(str) s = str.gsub(%r{[^/]+}n) { uri_segment($&) } PercentEncoded.new_no_dup(s) end # :stopdoc: def html_form_fast(pairs, sep='&') s = pairs.map {|k, v| # query-chars - pct-encoded - x-www-form-urlencoded-delimiters = # unreserved / "!" / "$" / "'" / "(" / ")" / "*" / "," / ":" / "@" / "/" / "?" # query-char - pct-encoded = unreserved / sub-delims / ":" / "@" / "/" / "?" # query-char = pchar / "/" / "?" = unreserved / pct-encoded / sub-delims / ":" / "@" / "/" / "?" # unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" # sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" # x-www-form-urlencoded-delimiters = "&" / "+" / ";" / "=" k = k.gsub(%r{[^0-9A-Za-z\-\._~:/?@!\$'()*,]}n) { '%' + $&.unpack("H2")[0].upcase } v = v.gsub(%r{[^0-9A-Za-z\-\._~:/?@!\$'()*,]}n) { '%' + $&.unpack("H2")[0].upcase } "#{k}=#{v}" }.join(sep) PercentEncoded.new_no_dup(s) end # :startdoc: # Escape.html_form composes HTML form key-value pairs as a x-www-form-urlencoded encoded string. # It returns an instance of PercentEncoded. # # Escape.html_form takes an array of pair of strings or # an hash from string to string. # # Escape.html_form([["a","b"], ["c","d"]]) #=> # # Escape.html_form({"a"=>"b", "c"=>"d"}) #=> # # # In the array form, it is possible to use same key more than once. # (It is required for a HTML form which contains # checkboxes and select element with multiple attribute.) # # Escape.html_form([["k","1"], ["k","2"]]) #=> # # # If the strings contains characters which must be escaped in x-www-form-urlencoded, # they are escaped using %-encoding. # # Escape.html_form([["k=","&;="]]) #=> # # # The separator can be specified by the optional second argument. # # Escape.html_form([["a","b"], ["c","d"]], ";") #=> # # # See HTML 4.01 for details. def html_form(pairs, sep='&') r = '' first = true pairs.each {|k, v| # query-chars - pct-encoded - x-www-form-urlencoded-delimiters = # unreserved / "!" / "$" / "'" / "(" / ")" / "*" / "," / ":" / "@" / "/" / "?" # query-char - pct-encoded = unreserved / sub-delims / ":" / "@" / "/" / "?" # query-char = pchar / "/" / "?" = unreserved / pct-encoded / sub-delims / ":" / "@" / "/" / "?" # unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" # sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" # x-www-form-urlencoded-delimiters = "&" / "+" / ";" / "=" r << sep if !first first = false k.each_byte {|byte| ch = byte.chr if %r{[^0-9A-Za-z\-\._~:/?@!\$'()*,]}n =~ ch r << "%" << ch.unpack("H2")[0].upcase else r << ch end } r << '=' v.each_byte {|byte| ch = byte.chr if %r{[^0-9A-Za-z\-\._~:/?@!\$'()*,]}n =~ ch r << "%" << ch.unpack("H2")[0].upcase else r << ch end } } PercentEncoded.new_no_dup(r) end class HTMLEscaped < StringWrapper end # :stopdoc: HTML_TEXT_ESCAPE_HASH = { '&' => '&', '<' => '<', '>' => '>', } # :startdoc: # Escape.html_text escapes a string appropriate for HTML text using character references. # It returns an instance of HTMLEscaped. # # It escapes 3 characters: # * '&' to '&' # * '<' to '<' # * '>' to '>' # # Escape.html_text("abc") #=> # # Escape.html_text("a & b < c > d") #=> # # # This function is not appropriate for escaping HTML element attribute # because quotes are not escaped. def html_text(str) s = str.gsub(/[&<>]/) {|ch| HTML_TEXT_ESCAPE_HASH[ch] } HTMLEscaped.new_no_dup(s) end # :stopdoc: HTML_ATTR_ESCAPE_HASH = { '&' => '&', '<' => '<', '>' => '>', '"' => '"', } # :startdoc: class HTMLAttrValue < StringWrapper end # Escape.html_attr_value encodes a string as a double-quoted HTML attribute using character references. # It returns an instance of HTMLAttrValue. # # Escape.html_attr_value("abc") #=> # # Escape.html_attr_value("a&b") #=> # # Escape.html_attr_value("ab&<>\"c") #=> # # Escape.html_attr_value("a'c") #=> # # # It escapes 4 characters: # * '&' to '&' # * '<' to '<' # * '>' to '>' # * '"' to '"' # def html_attr_value(str) s = '"' + str.gsub(/[&<>"]/) {|ch| HTML_ATTR_ESCAPE_HASH[ch] } + '"' HTMLAttrValue.new_no_dup(s) end end escape-0.2/VERSION0000644000000000000000000000000410571247750012363 0ustar rootroot0.2 escape-0.2/ChangeLog0000644000000000000000000000167110571164604013074 0ustar rootroot2007-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. escape-0.2/install.rb0000644000000000000000000000437310546772370013326 0ustar rootroot#!/usr/bin/env ruby # usage: ruby install.rb [-n] # options: # -n : don't install # # Author: Tanaka Akira require 'optparse' require 'fileutils' def target_directory $:.each {|loc| if %r{/site_ruby/[\d.]+\z} =~ 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 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.parse! } if $opt_n dir = target_directory collect_target.each {|filename| puts "-> #{dir}/#{filename}" } exit else File.umask 022 dir = target_directory collect_target.each {|filename| install_file filename, "#{dir}/#{filename}" } end escape-0.2/README0000644000000000000000000000540010571247750012200 0ustar rootroot= escape - HTML/URI/shell escaping utilities escape library provides several HTML/URI/shell escaping functions. == Author Tanaka Akira == Home Page (()) == 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: (()) * development version in Subversion repository: % svn co svn://svn@svn.a-k-r.org/akr/escape/trunk escape == Install % ruby install.rb == Reference Manual See rdoc/classes/Escape.html or (()) == 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. escape-0.2/Makefile0000644000000000000000000000012710570607377012765 0ustar rootrootrdoc: rdoc --op rdoc escape.rb README: misc/README.erb erb misc/README.erb > README