Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit bffe9df

Browse files
authored
FIX: we must properly encode objects prior to escaping (#891)
in cases of arrays escapeHTML will not work) *
1 parent c352054 commit bffe9df

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

lib/completions/anthropic_message_processor.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def to_xml_tool_calls(function_buffer)
3939
)
4040

4141
params = JSON.parse(tool_call.raw_json, symbolize_names: true)
42-
xml = params.map { |name, value| "<#{name}>#{CGI.escapeHTML(value)}</#{name}>" }.join("\n")
42+
xml =
43+
params.map { |name, value| "<#{name}>#{CGI.escapeHTML(value.to_s)}</#{name}>" }.join("\n")
4344

4445
node.at("tool_name").content = tool_call.name
4546
node.at("tool_id").content = tool_call.id

lib/completions/endpoints/gemini.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def add_to_function_buffer(function_buffer, payload: nil, partial: nil)
179179
if partial[:args]
180180
argument_fragments =
181181
partial[:args].reduce(+"") do |memo, (arg_name, value)|
182-
memo << "\n<#{arg_name}>#{CGI.escapeHTML(value)}</#{arg_name}>"
182+
memo << "\n<#{arg_name}>#{CGI.escapeHTML(value.to_s)}</#{arg_name}>"
183183
end
184184
argument_fragments << "\n"
185185

lib/completions/endpoints/open_ai.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def add_to_function_buffer(function_buffer, partial: nil, payload: nil)
173173

174174
argument_fragments =
175175
json_args.reduce(+"") do |memo, (arg_name, value)|
176-
memo << "\n<#{arg_name}>#{CGI.escapeHTML(value)}</#{arg_name}>"
176+
memo << "\n<#{arg_name}>#{CGI.escapeHTML(value.to_s)}</#{arg_name}>"
177177
end
178178
argument_fragments << "\n"
179179

0 commit comments

Comments
 (0)