Mercurial > hgrepos > hgweb.cgi > s4
view mpsplit.rb @ 997:f7cd4528926b draft
Warning message for BOM fixed
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Mon, 17 Oct 2022 17:11:04 +0859 |
parents | f2204bd941d5 |
children |
line wrap: on
line source
#!/usr/bin/env ruby21 # coding: binary require 'nkf' Encoding.default_external = Encoding::BINARY Encoding.default_internal = Encoding::BINARY boundary="--"+ARGV[0] # +"\r\n" tmpdir=(ARGV[1] || "tmp").dup tmpdir.untaint test(?d, tmpdir) or Dir.mkdir(tmpdir) stream=STDIN.readlines.join stream.split(boundary)[1..-2].each do |x| header = x.sub(/\r\n\r\n.*/, "") name = header.scan(/\bname=([\"']?)(.*?)\1/)[0][1] body = x.sub(/.*?\r\n\r\n/m, "").sub(/\r\n$/, "") STDERR.printf("body[%s]=[%s]\n", name, body.length) if /filename=(['\"]?)(.*?)\1/ =~ header && $2 > "" fn = $2 fn.untaint if File.dirname(fn)=="." open(File.expand_path(fn, tmpdir).untaint, "w") do |out| out.write body end ## printf("%s:filename=%s\n", name, fn) printf("%s:filename=%s\n", name, fn.unpack("H*")[0]) elsif /name=(['\"]?)(.*?)\1/ =~ header v=$2 printf("%s=%s\n", v, body.unpack("H*")[0]) end end