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)
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_id").content = tool_call.id

View File

@ -179,7 +179,7 @@ module DiscourseAi
if partial[:args]
argument_fragments =
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
argument_fragments << "\n"

View File

@ -173,7 +173,7 @@ module DiscourseAi
argument_fragments =
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
argument_fragments << "\n"