Skip to content

Commit dd29cdc

Browse files
koicandreibondarev
andauthored
Suppress a Ruby 3.4 warning for URI parser (#980)
This PR suppresses the following Ruby 3.4's warning. e.g.; ```console $ ruby -v ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-darwin24] $ RUBYOPT=-w bundle exec rspec spec/langchain/loader_spec.rb /Users/koic/src/github.com/patterns-ai-core/langchainrb/lib/langchain/loader.rb:94: warning: URI::RFC3986_PARSER.escape is obsolete. Use URI::RFC2396_PARSER.escape explicitly. ``` Compatibility with Ruby 3.1 supported by Langchain.rb is preserved. Co-authored-by: Andrei Bondarev <[email protected]>
1 parent d113c39 commit dd29cdc

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
- [DOCS]: Documentation changes. No changes to the library's behavior.
1010
- [SECURITY]: A change which fixes a security vulnerability.
1111

12+
## [Unreleased]
13+
- [COMPAT] [https://github.com/patterns-ai-core/langchainrb/pull/980] Suppress a Ruby 3.4 warning for URI parser.
14+
1215
## [0.19.5]
1316
- [BREAKING] [https://github.com/patterns-ai-core/langchainrb/pull/859] Add metadata support to PgVector storage
1417
- [BUGFIX] [https://github.com/patterns-ai-core/langchainrb/pull/939] Fix Langchain::Vectorsearch::Milvus initializer by passing :api_key

lib/langchain/assistant/messages/ollama_message.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ class OllamaMessage < Base
2424
def initialize(role:, content: nil, image_url: nil, tool_calls: [], tool_call_id: nil)
2525
raise ArgumentError, "Role must be one of #{ROLES.join(", ")}" unless ROLES.include?(role)
2626
raise ArgumentError, "Tool calls must be an array of hashes" unless tool_calls.is_a?(Array) && tool_calls.all? { |tool_call| tool_call.is_a?(Hash) }
27-
raise ArgumentError, "image_url must be a valid url" if image_url && !URI::DEFAULT_PARSER.make_regexp.match?(image_url)
27+
28+
# Ensure compatibility with `URI::RFC2396_PARSER` (Ruby 3.4+) and `URI::DEFAULT_PARSER` (<= 3.3).
29+
uri_parser = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::DEFAULT_PARSER
30+
raise ArgumentError, "image_url must be a valid url" if image_url && !uri_parser.make_regexp.match?(image_url)
2831

2932
@role = role
3033
# Some Tools return content as a JSON hence `.to_s`

lib/langchain/loader.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ def load(&block)
9191

9292
def load_from_url
9393
unescaped_url = URI.decode_www_form_component(@path)
94-
escaped_url = URI::DEFAULT_PARSER.escape(unescaped_url)
94+
95+
# Ensure compatibility with `URI::RFC2396_PARSER` (Ruby 3.4+) and `URI::DEFAULT_PARSER` (<= 3.3).
96+
uri_parser = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::DEFAULT_PARSER
97+
escaped_url = uri_parser.escape(unescaped_url)
98+
9599
URI.parse(escaped_url).open
96100
end
97101

lib/langchain/processors/eml.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ def extract_text_content(mail)
5252

5353
# Clean and format the extracted content
5454
def clean_content(content)
55+
# Ensure compatibility with `URI::RFC2396_PARSER` (Ruby 3.4+) and `URI::DEFAULT_PARSER` (<= 3.3).
56+
uri_parser = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::DEFAULT_PARSER
57+
5558
content
5659
.gsub(/\[cid:[^\]]+\]/, "") # Remove embedded image references
57-
.gsub(URI::DEFAULT_PARSER.make_regexp(%w[http https])) { |match| "<#{match}>" } # Format URLs
60+
.gsub(uri_parser.make_regexp(%w[http https])) { |match| "<#{match}>" } # Format URLs
5861
.gsub(/\r\n?/, "\n") # Normalize line endings to Unix style
5962
.gsub(/[\u200B-\u200D\uFEFF]/, "") # Remove zero width spaces and similar characters
6063
.gsub(/<\/?[^>]+>/, "") # Remove any HTML tags that might have sneaked in

0 commit comments

Comments
 (0)