Skip to content

Backport(v1.16): parser: use URI#open instead of URI.open (#4848) #4922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/fluent/config/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,23 @@ def process_include(attrs, elems, uri, allow_include = true)
else
basepath = '/'
fname = path
require 'open-uri'
URI.open(uri) {|f|
parser_proc = ->(f) {
Parser.new(basepath, f.each_line, fname).parse!(allow_include, nil, attrs, elems)
}

case u.scheme
when 'http', 'https', 'ftp'
# URI#open can be able to handle URIs for http, https and ftp.
require 'open-uri'
u.open(&parser_proc)
else
# TODO: This case should be handled in the previous if condition. Glob is not applied to some Windows path formats.
# 'c:/path/to/file' will be passed as URI, 'uri' and 'u.path' will be:
# - uri is 'c:/path/to/file'
# - u.path is '/path/to/file' and u.scheme is 'c'
# Therefore, the condition of the if statement above is not met and it is handled here.
File.open(u.path, &parser_proc)
end
end

rescue SystemCallError => e
Expand All @@ -104,4 +117,3 @@ def process_include(attrs, elems, uri, allow_include = true)
end
end
end

Loading