chupa-text 1.0.9 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 683591985ea7d93bfde2dc2643964120d18c6a04
4
- data.tar.gz: e0b1419f2d3a020d4036afbeb56c4b1366b8e4d8
3
+ metadata.gz: 07fabf59599faf7e5360e69c08e7d79614294099
4
+ data.tar.gz: e92e9800b47c7dc056b6232e371513832d18ded6
5
5
  SHA512:
6
- metadata.gz: c9b33ecfc733c19827d0ce2a8484f7cd4a128a1435616dae03bf42707b11e8c99bd3402b885fa2af073424a87e786220008f8bf5c02912aaad5874a1f9a5add4
7
- data.tar.gz: 85f8df4be72276db69c8938120c9ccd99bbf424493cf69f8b2357cb5e81053da9fcc35c386c3d1816ad53ea39d3de478ee9606e49783e2ed9b74631296cc413a
6
+ metadata.gz: f5d45be9f36b34dcc0987860b17f4e37808a7541acf74bc074e5c9c088b49d394ec5b4e0984d2c67686b6695450d4132effe7273c42c8786291de0c4e3619651
7
+ data.tar.gz: bf1e91f18a9e5206ef85f85afc522b86764a4ac4d09e1e3e3be38a35a26c05c5ecd051d41094b33acbd667e1ca0ab3e9b01e83f7400e9167a1ec3154bc243ff4
data/doc/text/news.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # News
2
2
 
3
+ ## 1.1.0: 2017-07-12
4
+
5
+ ### Improvements
6
+
7
+ * Supported external command limitation by the following environment
8
+ variables:
9
+
10
+ * `CHUPA_TEXT_EXTERNAL_COMMAND_LIMIT_CPU`
11
+
12
+ * `CHUPA_TEXT_EXTERNAL_COMMAND_LIMIT_AS`
13
+
14
+ * Handled more download errors.
15
+
16
+ * Improved extension detection.
17
+
3
18
  ## 1.0.9: 2017-07-11
4
19
 
5
20
  ### Improvements
@@ -166,7 +166,11 @@ module ChupaText
166
166
  # lower case like `pdf` not `PDF`.
167
167
  def extension
168
168
  return nil if @uri.nil?
169
- File.extname(@uri.path).downcase.gsub(/\A\./, "")
169
+ if @uri.is_a?(URI::HTTP) and @uri.path.end_with?("/")
170
+ "html"
171
+ else
172
+ File.extname(@uri.path).downcase.gsub(/\A\./, "")
173
+ end
170
174
  end
171
175
 
172
176
  # @return [Bool] true if MIME type is "text/XXX", false
@@ -56,6 +56,8 @@ module ChupaText
56
56
  end
57
57
 
58
58
  class SpawnLimitOptions
59
+ include Loggable
60
+
59
61
  attr_reader :options
60
62
  def initialize
61
63
  @options = {}
@@ -65,13 +67,16 @@ module ChupaText
65
67
  private
66
68
  def set_default_options
67
69
  set_option(:cpu, :int)
68
- set_option(:rss, :size)
69
70
  set_option(:as, :size)
70
71
  end
71
72
 
72
73
  def set_option(key, type)
73
- value = ENV["CHUPA_EXTERNAL_COMMAND_LIMIT_#{key.to_s.upcase}"]
74
+ value =
75
+ ENV["CHUPA_TEXT_EXTERNAL_COMMAND_LIMIT_#{key.to_s.upcase}"] ||
76
+ # For backward compatibility
77
+ ENV["CHUPA_EXTERNAL_COMMAND_LIMIT_#{key.to_s.upcase}"]
74
78
  return if value.nil?
79
+ return if value.empty?
75
80
  value = send("parse_#{type}", key, value)
76
81
  return if value.nil?
77
82
  rlimit_number = Process.const_get("RLIMIT_#{key.to_s.upcase}")
@@ -81,8 +86,17 @@ module ChupaText
81
86
  return nil
82
87
  end
83
88
  limit_info = "soft-limit:#{soft_limit}, hard-limit:#{hard_limit}"
84
- log(:info, "[#{key}][set] <#{value}>(#{limit_info})")
85
- @options[:"rlimit_#{key}"] = value
89
+ info("#{log_tag}[#{key}][set] <#{value}>(#{limit_info})")
90
+
91
+ # TODO: Workaround for Ruby 2.3.3p222
92
+ case key
93
+ when :cpu
94
+ @options[:rlimit_cpu] = value
95
+ when :as
96
+ @options[:rlimit_as] = value
97
+ else
98
+ @options[:"rlimit_#{key}"] = value
99
+ end
86
100
  end
87
101
 
88
102
  def parse_int(key, value)
@@ -122,15 +136,15 @@ module ChupaText
122
136
  end
123
137
 
124
138
  def log_hard_limit_over_value(key, value, hard_limit)
125
- log(:warning, "[#{key}][large] <#{value}>(hard-limit:#{hard_limit})")
139
+ warn("#{log_tag}[#{key}][large] <#{value}>(hard-limit:#{hard_limit})")
126
140
  end
127
141
 
128
142
  def log_invalid_value(key, value, type)
129
- log(:warning, "[#{key}][invalid] <#{value}>(#{type})")
143
+ warn("#{log_tag}[#{key}][invalid] <#{value}>(#{type})")
130
144
  end
131
145
 
132
- def log(level, message)
133
- ChupaText.logger.send(level, "[external-command][limit]#{message}")
146
+ def log_tag
147
+ "[external-command][limit]"
134
148
  end
135
149
  end
136
150
  end
@@ -45,15 +45,15 @@ module ChupaText
45
45
 
46
46
  private
47
47
  def download
48
- path = @uri.path
49
- path += "index.html" if path.end_with?("/")
50
48
  begin
51
49
  @uri.open("rb") do |input|
52
50
  self.mime_type = input.content_type.split(/;/).first
53
- VirtualContent.new(input, path)
51
+ VirtualContent.new(input, @uri.path)
54
52
  end
55
53
  rescue OpenURI::HTTPError => error
56
54
  raise DownloadError.new(@uri, error.message.strip)
55
+ rescue => error
56
+ raise DownloadError.new(@uri, "#{error.class}: #{error.message}")
57
57
  end
58
58
  end
59
59
  end
@@ -18,8 +18,8 @@ module ChupaText
18
18
  class TextData < Data
19
19
  def initialize(text, options={})
20
20
  super(options)
21
- self.uri = uri.to_s.gsub(/\.[^.]+\z/, ".txt")
22
- self.path = path.to_s.gsub(/\.[^.]+\z/, ".txt")
21
+ self.uri = uri.to_s.gsub(/\.[a-z\d]+\z/i, ".txt")
22
+ self.path = path.to_s.gsub(/\.[a-z\d]+\z/i, ".txt")
23
23
  self.mime_type = "text/plain"
24
24
  self.body = text
25
25
  self.size = text.bytesize
@@ -15,5 +15,5 @@
15
15
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
  module ChupaText
18
- VERSION = "1.0.9"
18
+ VERSION = "1.1.0"
19
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chupa-text
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-11 00:00:00.000000000 Z
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: archive-zip