template-ruby 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e240c31089e37775df02ba1ea0646922413b26860318456d19ed5d2b38ed077
4
- data.tar.gz: 25f45bb4ef78e1f62e63a960ce3fa46245b60dfab8fd96a273caf823ee2b016f
3
+ metadata.gz: d5e2a863316056d011b034cc0c819984d710899e8b51657dd15636e45db058b0
4
+ data.tar.gz: 47974cad2e705fb70706b68a496523f414b3027c6f57ec6d22344c588cdce143
5
5
  SHA512:
6
- metadata.gz: a2870be4d39f138c269946c935985d2de54c4364307630011b8de8095d50dd7a72de3a71f401414c64e416832c2d4f6e9a8e92d7e6038855725e35c7e0cbbdd9
7
- data.tar.gz: 77fd004c7464e2715726dfec039925e8c4653d6a78993cf6d1c6cecb717f08fcb5e04f9cebf7acf130bb3ed7fcac7891e65ef8fe0db37ab9c66724ef9b2cd923
6
+ metadata.gz: 1ba52300910fb32458e115c200842c3a2ef18a19e8fddee92c38a961d60637d3c3c73906304184ef0ec5771ad85cc5dd19d8dbe0803a872a2c5c0dd69cc82a16
7
+ data.tar.gz: d526bbd95df4375aee06d4c9cc8bb8c6f2927b725514527dd9d3e29229223235bf0c8870d917eb61ae30cbce52e2c27a5f18ba31a2b1fcc94b0dfc574bf77bd1
data/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 0.2.3 / 2022-08-31
9
+
10
+ - Add default timeout for code and template parsing and evaluation
11
+
8
12
  ## 0.2.2 / 2022-08-31
9
13
 
10
14
  - Fix parsing error when the template is empty, e.g. ""
data/lib/code.rb CHANGED
@@ -1,22 +1,27 @@
1
1
  class Code
2
- def initialize(input, io: $stdout)
2
+ def initialize(input, io: $stdout, timeout: 10)
3
3
  @input = input
4
- @parsed = ::Code::Parser::Code.new.parse(@input)
4
+ @parsed = Timeout::timeout(timeout) do
5
+ ::Code::Parser::Code.new.parse(@input)
6
+ end
5
7
  @io = io
8
+ @timeout = timeout
6
9
  end
7
10
 
8
- def self.evaluate(input, context = "", io: $stdout)
9
- new(input, io: io).evaluate(context)
11
+ def self.evaluate(input, context = "", io: $stdout, timeout: 10)
12
+ new(input, io: io, timeout: timeout).evaluate(context)
10
13
  end
11
14
 
12
15
  def evaluate(context = "")
13
- if context.present?
14
- context = ::Code.evaluate(context)
15
- else
16
- context = ::Code::Object::Dictionnary.new
17
- end
16
+ Timeout::timeout(@timeout) do
17
+ if context.present?
18
+ context = ::Code.evaluate(context, timeout: @timeout)
19
+ else
20
+ context = ::Code::Object::Dictionnary.new
21
+ end
18
22
 
19
- ::Code::Node::Code.new(parsed).evaluate(context: context, io: @io)
23
+ ::Code::Node::Code.new(parsed).evaluate(context: context, io: @io)
24
+ end
20
25
  end
21
26
 
22
27
  private
data/lib/template-ruby.rb CHANGED
@@ -4,6 +4,7 @@ require "bigdecimal"
4
4
  require "active_support"
5
5
  require "active_support/core_ext/object/blank"
6
6
  require "stringio"
7
+ require "timeout"
7
8
 
8
9
  loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
9
10
  loader.ignore(__FILE__)
data/lib/template.rb CHANGED
@@ -1,25 +1,30 @@
1
1
  class Template
2
- VERSION = Gem::Version.new("0.2.2")
2
+ VERSION = Gem::Version.new("0.2.3")
3
3
 
4
- def initialize(input, io: StringIO.new)
4
+ def initialize(input, io: StringIO.new, timeout: 10)
5
5
  @input = input
6
- @parsed = ::Template::Parser::Template.new.parse(@input)
6
+ @parsed = Timeout::timeout(timeout) do
7
+ ::Template::Parser::Template.new.parse(@input)
8
+ end
7
9
  @io = io
10
+ @timeout = timeout
8
11
  end
9
12
 
10
- def self.render(input, context = "", io: StringIO.new)
11
- new(input, io: io).render(context)
13
+ def self.render(input, context = "", io: StringIO.new, timeout: 10)
14
+ new(input, io: io, timeout: timeout).render(context)
12
15
  end
13
16
 
14
17
  def render(context = "")
15
- if context.present?
16
- context = ::Code.evaluate(context)
17
- else
18
- context = ::Code::Object::Dictionnary.new
19
- end
18
+ Timeout::timeout(@timeout) do
19
+ if context.present?
20
+ context = ::Code.evaluate(context, timeout: @timeout)
21
+ else
22
+ context = ::Code::Object::Dictionnary.new
23
+ end
20
24
 
21
- ::Template::Node::Template.new(@parsed).evaluate(context: context, io: @io)
25
+ ::Template::Node::Template.new(@parsed).evaluate(context: context, io: @io)
22
26
 
23
- @io.is_a?(StringIO) ? @io.string : nil
27
+ @io.is_a?(StringIO) ? @io.string : nil
28
+ end
24
29
  end
25
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: template-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié