diff --git a/CHANGELOG.md b/CHANGELOG.md index a944ad05b..f7a6f68f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ - [DOCS]: Documentation changes. No changes to the library's behavior. - [SECURITY]: A change which fixes a security vulnerability. +## [Unreleased] +- [COMPAT] [https://github.com/patterns-ai-core/langchainrb/pull/980] Suppress a Ruby 3.4 warning for URI parser. + ## [0.19.5] - [BREAKING] [https://github.com/patterns-ai-core/langchainrb/pull/859] Add metadata support to PgVector storage - [BUGFIX] [https://github.com/patterns-ai-core/langchainrb/pull/939] Fix Langchain::Vectorsearch::Milvus initializer by passing :api_key diff --git a/lib/langchain/assistant/messages/ollama_message.rb b/lib/langchain/assistant/messages/ollama_message.rb index d660ff802..d2067dc31 100644 --- a/lib/langchain/assistant/messages/ollama_message.rb +++ b/lib/langchain/assistant/messages/ollama_message.rb @@ -24,7 +24,10 @@ class OllamaMessage < Base def initialize(role:, content: nil, image_url: nil, tool_calls: [], tool_call_id: nil) raise ArgumentError, "Role must be one of #{ROLES.join(", ")}" unless ROLES.include?(role) 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) } - raise ArgumentError, "image_url must be a valid url" if image_url && !URI::DEFAULT_PARSER.make_regexp.match?(image_url) + + # Ensure compatibility with `URI::RFC2396_PARSER` (Ruby 3.4+) and `URI::DEFAULT_PARSER` (<= 3.3). + uri_parser = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::DEFAULT_PARSER + raise ArgumentError, "image_url must be a valid url" if image_url && !uri_parser.make_regexp.match?(image_url) @role = role # Some Tools return content as a JSON hence `.to_s` diff --git a/lib/langchain/loader.rb b/lib/langchain/loader.rb index 94953a7fb..632f6d16e 100644 --- a/lib/langchain/loader.rb +++ b/lib/langchain/loader.rb @@ -91,7 +91,11 @@ def load(&block) def load_from_url unescaped_url = URI.decode_www_form_component(@path) - escaped_url = URI::DEFAULT_PARSER.escape(unescaped_url) + + # Ensure compatibility with `URI::RFC2396_PARSER` (Ruby 3.4+) and `URI::DEFAULT_PARSER` (<= 3.3). + uri_parser = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::DEFAULT_PARSER + escaped_url = uri_parser.escape(unescaped_url) + URI.parse(escaped_url).open end diff --git a/lib/langchain/processors/eml.rb b/lib/langchain/processors/eml.rb index 3160e9beb..eb47f7bec 100644 --- a/lib/langchain/processors/eml.rb +++ b/lib/langchain/processors/eml.rb @@ -52,9 +52,12 @@ def extract_text_content(mail) # Clean and format the extracted content def clean_content(content) + # Ensure compatibility with `URI::RFC2396_PARSER` (Ruby 3.4+) and `URI::DEFAULT_PARSER` (<= 3.3). + uri_parser = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::DEFAULT_PARSER + content .gsub(/\[cid:[^\]]+\]/, "") # Remove embedded image references - .gsub(URI::DEFAULT_PARSER.make_regexp(%w[http https])) { |match| "<#{match}>" } # Format URLs + .gsub(uri_parser.make_regexp(%w[http https])) { |match| "<#{match}>" } # Format URLs .gsub(/\r\n?/, "\n") # Normalize line endings to Unix style .gsub(/[\u200B-\u200D\uFEFF]/, "") # Remove zero width spaces and similar characters .gsub(/<\/?[^>]+>/, "") # Remove any HTML tags that might have sneaked in