Skip to content

Commit 0254d7e

Browse files
committed
v1_parser: use URI#open instead of URI.open
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
1 parent 1fa4f94 commit 0254d7e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/fluent/config/v1_parser.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,22 @@ def eval_include(attrs, elems, uri)
169169
V1Parser.new(ss, basepath, fname, @eval_context).parse_element(true, nil, attrs, elems)
170170
}
171171
else
172-
require 'open-uri'
173172
basepath = '/'
174173
fname = path
175-
data = URI.open(uri) { |f| f.read }
174+
175+
case u.scheme
176+
when 'http', 'https', 'ftp'
177+
# URI#open can be able to handle URIs for http, https and ftp.
178+
require 'open-uri'
179+
data = u.open { |f| f.read }
180+
else
181+
# TODO: This case should be handled in the previous if condition. Glob is not applied to some Windows path formats.
182+
# 'c:/path/to/file' will be passed as URI, 'uri' and 'u.path' will be:
183+
# - uri is 'c:/path/to/file'
184+
# - u.path is '/path/to/file' and u.scheme is 'c'
185+
# Therefore, the condition of the if statement above is not met and it is handled here.
186+
data = File.open(u.path) { |f| f.read }
187+
end
176188
data.force_encoding('UTF-8')
177189
ss = StringScanner.new(data)
178190
V1Parser.new(ss, basepath, fname, @eval_context).parse_element(true, nil, attrs, elems)

0 commit comments

Comments
 (0)