Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-23 01:40:29 +01:00
Merge pull request #236 from paviliondev/liquid_template_error_handling
Ensure we're not interpolating an object
Dieser Commit ist enthalten in:
Commit
759358e081
3 geänderte Dateien mit 47 neuen und 3 gelöschten Zeilen
|
@ -44,7 +44,7 @@ class CustomWizard::Mapper
|
||||||
|
|
||||||
def initialize(params)
|
def initialize(params)
|
||||||
@inputs = params[:inputs] || {}
|
@inputs = params[:inputs] || {}
|
||||||
@data = params[:data] || {}
|
@data = params[:data].with_indifferent_access || {}
|
||||||
@user = params[:user]
|
@user = params[:user]
|
||||||
@opts = params[:opts] || {}
|
@opts = params[:opts] || {}
|
||||||
end
|
end
|
||||||
|
@ -267,7 +267,12 @@ class CustomWizard::Mapper
|
||||||
return nil if data.nil?
|
return nil if data.nil?
|
||||||
k = keys.shift
|
k = keys.shift
|
||||||
result = data[k]
|
result = data[k]
|
||||||
keys.empty? ? result : self.recurse(result, keys)
|
|
||||||
|
if keys.empty?
|
||||||
|
result.is_a?(Object) ? "" : result
|
||||||
|
else
|
||||||
|
self.recurse(result, keys)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def bool(value)
|
def bool(value)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
# name: discourse-custom-wizard
|
# name: discourse-custom-wizard
|
||||||
# about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more.
|
# about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more.
|
||||||
# version: 2.2.13
|
# version: 2.2.14
|
||||||
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever
|
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever
|
||||||
# url: https://github.com/paviliondev/discourse-custom-wizard
|
# url: https://github.com/paviliondev/discourse-custom-wizard
|
||||||
# contact_emails: development@pavilion.tech
|
# contact_emails: development@pavilion.tech
|
||||||
|
|
|
@ -58,6 +58,11 @@ describe CustomWizard::Mapper do
|
||||||
"step_1_field_3" => "Value"
|
"step_1_field_3" => "Value"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let(:template_params_object) {
|
||||||
|
{
|
||||||
|
"step_1_field_1": get_wizard_fixture("field/upload")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def create_template_mapper(data, user)
|
def create_template_mapper(data, user)
|
||||||
CustomWizard::Mapper.new(
|
CustomWizard::Mapper.new(
|
||||||
|
@ -448,6 +453,40 @@ describe CustomWizard::Mapper do
|
||||||
expect(result).to eq(template)
|
expect(result).to eq(template)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "handles correct object variable references" do
|
||||||
|
template = <<-LIQUID.strip
|
||||||
|
{%- if "w{step_1_field_1.id}" == "step_2_field_7" -%}
|
||||||
|
Correct
|
||||||
|
{%- else -%}
|
||||||
|
Incorrect
|
||||||
|
{%-endif-%}
|
||||||
|
LIQUID
|
||||||
|
mapper = create_template_mapper(template_params_object, user1)
|
||||||
|
result = mapper.interpolate(
|
||||||
|
template.dup,
|
||||||
|
template: true,
|
||||||
|
wizard: true
|
||||||
|
)
|
||||||
|
expect(result).to eq("Correct")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "handles incorrect object variable references" do
|
||||||
|
template = <<-LIQUID.strip
|
||||||
|
{%- if "w{step_1_field_1}" == "step_2_field_7" -%}
|
||||||
|
Correct
|
||||||
|
{%- else -%}
|
||||||
|
Incorrect
|
||||||
|
{%-endif-%}
|
||||||
|
LIQUID
|
||||||
|
mapper = create_template_mapper(template_params_object, user1)
|
||||||
|
result = mapper.interpolate(
|
||||||
|
template.dup,
|
||||||
|
template: true,
|
||||||
|
wizard: true
|
||||||
|
)
|
||||||
|
expect(result).to eq("Incorrect")
|
||||||
|
end
|
||||||
|
|
||||||
context "custom filter: 'first_non_empty'" do
|
context "custom filter: 'first_non_empty'" do
|
||||||
it "gives first non empty element from list" do
|
it "gives first non empty element from list" do
|
||||||
template = <<-LIQUID.strip
|
template = <<-LIQUID.strip
|
||||||
|
|
Laden …
In neuem Issue referenzieren