1
0
Fork 0

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 end
if opts[:wizard] 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 end
if opts[:value] if opts[:value]

Datei anzeigen

@ -459,5 +459,20 @@ describe CustomWizard::Mapper do
expect(result).to eq("") expect(result).to eq("")
end end
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
end end