0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-12-04 22:31:09 +01:00

Replace curly braces with braces in user entered content

Dieser Commit ist enthalten in:
Angus McLeod 2022-04-29 12:18:47 +02:00
Ursprung 449b81a93e
Commit c009d780a1
2 geänderte Dateien mit 21 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -232,7 +232,12 @@ class CustomWizard::Mapper
end
if opts[:wizard]
string.gsub!(/w\{(.*?)\}/) { |match| recurse(data, [*$1.split('.')]) || '' }
string.gsub!(/w\{(.*?)\}/) do |match|
content = recurse(data, [*$1.split('.')]) || ''
# Curly braces are used by liquid, so they can't be part of the content.
# TODO: Ideally these would be escaped somehow.
content.gsub(/{/, "(").gsub(/}/, ")") if opts[:template]
end
end
if opts[:value]

Datei anzeigen

@ -459,5 +459,20 @@ describe CustomWizard::Mapper do
expect(result).to eq("")
end
end
it "replaces curly braces in user content with braces" do
params_with_curly_braces = {
"step_1_field_1" => "Some code with braces {%s}"
}
template = "w{step_1_field_1}"
mapper = create_template_mapper(params_with_curly_braces, user1)
result = mapper.interpolate(
template.dup,
template: true,
user: true,
wizard: true
)
expect(result).to eq("Some code with braces (%s)")
end
end
end