asciidoctor-include-ext 0.3.1 → 0.4.0

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: 7ebb6ec82e190f28ee47dae11c6e6690ee3e8f544edf185c5c227570bf665476
4
- data.tar.gz: 4eaadde9222a5d86e90544501ebcda0099ad8ee04b94fefc187502297640175b
3
+ metadata.gz: e351222783e131005427ad519891508168603495508299c6d71c2fb55d71a19e
4
+ data.tar.gz: 209424da5377db4f71f273f32413f69d083faec1ee9da79cf127d7ed55a57c62
5
5
  SHA512:
6
- metadata.gz: ff4e777544c8236442d30e454cf3720360592e29fcc40d0ee974f8d0544ace610cbf3caadeee6c8712ab71e7e6ff1feae5f59a3669e7c7e8056a711e45358c3d
7
- data.tar.gz: 454bdd6eef9671098f00b7bb32a67acfcbb0c5800c55eb5a805e52ff1341ed5dd0c56a36d94668777a7d613e91e1bb27592b3448509b130e469c0d80e0a16c0b
6
+ metadata.gz: b93df9f785ad62e1b36a8a68207f06f57578f6ee54af248596c17aa0be38c58e15175ca1cbc02bbe1a73338306959d9a99b06181948fb5743461510cfa02fb4f
7
+ data.tar.gz: 6ec6deec461722db7a314fb21726af6d08572690e1785865d83a0b3668df43781e9015b87966556b9b2982f434d7eda597eaedd7dcbe56af241e09e1017b8a4b
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright 2017 Jakub Jirutka <jakub@jirutka.cz>.
3
+ Copyright 2017-present Jakub Jirutka <jakub@jirutka.cz>.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.adoc CHANGED
@@ -7,7 +7,7 @@
7
7
  :codacy-id: 45320444129044688ef6553821b083f1
8
8
 
9
9
  ifdef::env-github[]
10
- image:https://travis-ci.org/{gh-name}.svg?branch={gh-branch}[Build Status, link="https://travis-ci.org/{gh-name}"]
10
+ image:https://github.com/{gh-name}/workflows/CI/badge.svg[CI Status, link=https://github.com/{gh-name}/actions?query=workflow%3A%22CI%22]
11
11
  image:https://api.codacy.com/project/badge/Coverage/{codacy-id}["Test Coverage", link="https://www.codacy.com/app/{gh-name}"]
12
12
  image:https://api.codacy.com/project/badge/Grade/{codacy-id}["Codacy Code quality", link="https://www.codacy.com/app/{gh-name}"]
13
13
  image:https://img.shields.io/gem/v/{gem-name}.svg?style=flat[Gem Version, link="https://rubygems.org/gems/{gem-name}"]
@@ -49,6 +49,9 @@ or to install the latest development version:
49
49
  gem install {gem-name} --pre
50
50
 
51
51
 
52
+ WARNING: Versions *prior 0.4.0* are vulnerable for Command Injection (see https://github.com/{gh-name}/commit/c7ea001a597c7033575342c51483dab7b87ae155[c7ea001] for more information). If you use an older version, update to 0.4.0 immediately!
53
+
54
+
52
55
  == Usage
53
56
 
54
57
  Just `require '{gem-name}'`.
@@ -1,4 +1,4 @@
1
- require File.expand_path('../lib/asciidoctor/include_ext/version', __FILE__)
1
+ require File.expand_path('lib/asciidoctor/include_ext/version', __dir__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'asciidoctor-include-ext'
@@ -9,24 +9,22 @@ Gem::Specification.new do |s|
9
9
  s.license = 'MIT'
10
10
 
11
11
  s.summary = "Asciidoctor's standard include::[] processor reimplemented as an extension"
12
- s.description = <<EOF
13
- This is a reimplementation of the Asciidoctor's built-in (pre)processor for the
14
- include::[] directive in extensible and more clean way. It provides the same
15
- features, but you can easily adjust it or extend for your needs. For example,
16
- you can change how it loads included files or add another ways how to select
17
- portions of the document to include.
18
- EOF
12
+ s.description = <<~EOF
13
+ This is a reimplementation of the Asciidoctor's built-in (pre)processor for the
14
+ include::[] directive in extensible and more clean way. It provides the same
15
+ features, but you can easily adjust it or extend for your needs. For example,
16
+ you can change how it loads included files or add another ways how to select
17
+ portions of the document to include.
18
+ EOF
19
19
 
20
20
  s.files = Dir['lib/**/*', '*.gemspec', 'LICENSE*', 'README*']
21
- s.has_rdoc = 'yard'
22
21
 
23
- s.required_ruby_version = '>= 2.1'
22
+ s.required_ruby_version = '>= 2.3'
24
23
 
25
24
  s.add_runtime_dependency 'asciidoctor', '>= 1.5.6', '< 3.0.0'
26
25
 
27
- s.add_development_dependency 'corefines', '~> 1.11'
28
- s.add_development_dependency 'kramdown', '~> 1.16'
29
- s.add_development_dependency 'rake', '~> 12.0'
26
+ s.add_development_dependency 'kramdown', '~> 2.0'
27
+ s.add_development_dependency 'rake', '~> 13.0'
30
28
  s.add_development_dependency 'rspec', '~> 3.7'
31
29
  s.add_development_dependency 'rubocop', '~> 0.51.0'
32
30
  s.add_development_dependency 'simplecov', '~> 0.15'
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require 'logger'
3
3
  require 'open-uri'
4
+ require 'uri'
4
5
 
5
6
  require 'asciidoctor/include_ext/version'
6
7
  require 'asciidoctor/include_ext/reader_ext'
@@ -86,7 +87,7 @@ module Asciidoctor::IncludeExt
86
87
 
87
88
  return false if doc.safe >= ::Asciidoctor::SafeMode::SECURE
88
89
  return false if doc.attributes.fetch('max-include-depth', 64).to_i < 1
89
- return false if target_uri?(target) && !doc.attributes.key?('allow-uri-read')
90
+ return false if target_http?(target) && !doc.attributes.key?('allow-uri-read')
90
91
  true
91
92
  end
92
93
 
@@ -94,7 +95,7 @@ module Asciidoctor::IncludeExt
94
95
  # @param reader (see #process)
95
96
  # @return [String, nil] file path or URI of the *target*, or `nil` if not found.
96
97
  def resolve_target_path(target, reader)
97
- return target if target_uri? target
98
+ return target if target_http? target
98
99
 
99
100
  # Include file is resolved relative to dir of the current include,
100
101
  # or base_dir if within original docfile.
@@ -106,16 +107,22 @@ module Asciidoctor::IncludeExt
106
107
  # Reads the specified file as individual lines, filters them using the
107
108
  # *selector* (if provided) and returns those lines in an array.
108
109
  #
109
- # @param filename [String] path of the file to be read.
110
+ # @param path [String] URL or path of the file to be read.
110
111
  # @param selector [#to_proc, nil] predicate to filter lines that should be
111
112
  # included in the output. It must accept two arguments: line and
112
113
  # the line number. If `nil` is given, all lines are passed.
113
114
  # @return [Array<String>] an array of read lines.
114
- def read_lines(filename, selector)
115
- if selector
116
- IO.foreach(filename).select.with_index(1, &selector)
117
- else
118
- open(filename, &:read)
115
+ def read_lines(path, selector)
116
+ # IO.open is deliberately not used directly to avoid potential security risks.
117
+ # TODO: Get rid of 'open-uri' (URI.open).
118
+ io = target_http?(path) ? URI : File
119
+
120
+ io.open(path) do |f|
121
+ if selector
122
+ f.each.select.with_index(1, &selector)
123
+ else
124
+ f.read
125
+ end
119
126
  end
120
127
  end
121
128
 
@@ -142,9 +149,13 @@ module Asciidoctor::IncludeExt
142
149
  private
143
150
 
144
151
  # @param target (see #process)
145
- # @return [Boolean] `true` if the *target* is an URI, `false` otherwise.
146
- def target_uri?(target)
147
- ::Asciidoctor::Helpers.uriish?(target)
152
+ # @return [Boolean] `true` if the *target* is a valid HTTP(S) URI, `false` otherwise.
153
+ def target_http?(target)
154
+ # First do a fast test, then try to parse it.
155
+ target.downcase.start_with?('http://', 'https://') \
156
+ && URI.parse(target).is_a?(URI::HTTP)
157
+ rescue URI::InvalidURIError
158
+ false
148
159
  end
149
160
  end
150
161
  end
@@ -3,6 +3,6 @@
3
3
  module Asciidoctor
4
4
  module IncludeExt
5
5
  # Version of the asciidoctor-include-ext gem.
6
- VERSION = '0.3.1'.freeze
6
+ VERSION = '0.4.0'.freeze
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-include-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Jirutka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-14 00:00:00.000000000 Z
11
+ date: 2022-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -30,48 +30,34 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 3.0.0
33
- - !ruby/object:Gem::Dependency
34
- name: corefines
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '1.11'
40
- type: :development
41
- prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: '1.11'
47
33
  - !ruby/object:Gem::Dependency
48
34
  name: kramdown
49
35
  requirement: !ruby/object:Gem::Requirement
50
36
  requirements:
51
37
  - - "~>"
52
38
  - !ruby/object:Gem::Version
53
- version: '1.16'
39
+ version: '2.0'
54
40
  type: :development
55
41
  prerelease: false
56
42
  version_requirements: !ruby/object:Gem::Requirement
57
43
  requirements:
58
44
  - - "~>"
59
45
  - !ruby/object:Gem::Version
60
- version: '1.16'
46
+ version: '2.0'
61
47
  - !ruby/object:Gem::Dependency
62
48
  name: rake
63
49
  requirement: !ruby/object:Gem::Requirement
64
50
  requirements:
65
51
  - - "~>"
66
52
  - !ruby/object:Gem::Version
67
- version: '12.0'
53
+ version: '13.0'
68
54
  type: :development
69
55
  prerelease: false
70
56
  version_requirements: !ruby/object:Gem::Requirement
71
57
  requirements:
72
58
  - - "~>"
73
59
  - !ruby/object:Gem::Version
74
- version: '12.0'
60
+ version: '13.0'
75
61
  - !ruby/object:Gem::Dependency
76
62
  name: rspec
77
63
  requirement: !ruby/object:Gem::Requirement
@@ -162,14 +148,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
148
  requirements:
163
149
  - - ">="
164
150
  - !ruby/object:Gem::Version
165
- version: '2.1'
151
+ version: '2.3'
166
152
  required_rubygems_version: !ruby/object:Gem::Requirement
167
153
  requirements:
168
154
  - - ">="
169
155
  - !ruby/object:Gem::Version
170
156
  version: '0'
171
157
  requirements: []
172
- rubygems_version: 3.0.3
158
+ rubygems_version: 3.3.7
173
159
  signing_key:
174
160
  specification_version: 4
175
161
  summary: Asciidoctor's standard include::[] processor reimplemented as an extension