FIX: we must properly encode objects prior to escaping (#891)

in cases of arrays escapeHTML will not work)

*
This commit is contained in:
Sam 2024-11-04 16:16:25 +11:00 committed by GitHub
parent c352054d4e
commit bffe9dfa07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 3 deletions

View File

@ -39,7 +39,8 @@ class DiscourseAi::Completions::AnthropicMessageProcessor
) )
params = JSON.parse(tool_call.raw_json, symbolize_names: true) params = JSON.parse(tool_call.raw_json, symbolize_names: true)
xml = params.map { |name, value| "<#{name}>#{CGI.escapeHTML(value)}</#{name}>" }.join("\n") xml =
params.map { |name, value| "<#{name}>#{CGI.escapeHTML(value.to_s)}</#{name}>" }.join("\n")
node.at("tool_name").content = tool_call.name node.at("tool_name").content = tool_call.name
node.at("tool_id").content = tool_call.id node.at("tool_id").content = tool_call.id

View File

@ -179,7 +179,7 @@ module DiscourseAi
if partial[:args] if partial[:args]
argument_fragments = argument_fragments =
partial[:args].reduce(+"") do |memo, (arg_name, value)| partial[:args].reduce(+"") do |memo, (arg_name, value)|
memo << "\n<#{arg_name}>#{CGI.escapeHTML(value)}</#{arg_name}>" memo << "\n<#{arg_name}>#{CGI.escapeHTML(value.to_s)}</#{arg_name}>"
end end
argument_fragments << "\n" argument_fragments << "\n"

View File

@ -173,7 +173,7 @@ module DiscourseAi
argument_fragments = argument_fragments =
json_args.reduce(+"") do |memo, (arg_name, value)| json_args.reduce(+"") do |memo, (arg_name, value)|
memo << "\n<#{arg_name}>#{CGI.escapeHTML(value)}</#{arg_name}>" memo << "\n<#{arg_name}>#{CGI.escapeHTML(value.to_s)}</#{arg_name}>"
end end
argument_fragments << "\n" argument_fragments << "\n"