OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Escape project custom field list values in the search results and refactor search specs.
Dombi Attila9dfe80c0985c
diff --git a/lib_static/plugins/acts_as_searchable/lib/acts_as_searchable.rb b/lib_static/plugins/acts_as_searchable/lib/acts_as_searchable.rbindex 5ab1db7c347..884f5c38c17 100644--- a/lib_static/plugins/acts_as_searchable/lib/acts_as_searchable.rb+++ b/lib_static/plugins/acts_as_searchable/lib/acts_as_searchable.rb@@ -106,7 +106,7 @@ module Redmineendnamed_tokens = tokens.each_with_object({}).with_index do |(token, acc), index|- acc[:"token_#{index}"] = "%#{token.downcase}%"+ acc[:"token_#{index}"] = "%#{sanitize_sql_like(token.downcase)}%"endfind_conditions = [sql, named_tokens]@@ -187,7 +187,7 @@ module RedmineON custom_options.custom_field_id = custom_values.custom_field_idAND custom_options.id::VARCHAR = custom_values.valueSQL- .where(customized_id: arel_table[:id])+ .where("customized_id=#{table_name}.id").where(custom_field_id: searchable_custom_field_ids).where("(custom_values.value ILIKE ?) OR (custom_options.value ILIKE ?)")diff --git a/spec/features/search/search_spec.rb b/spec/features/search/search_spec.rbindex c2cbb4f9f08..19f8af98caa 100644--- a/spec/features/search/search_spec.rb+++ b/spec/features/search/search_spec.rb@@ -478,81 +478,85 @@ RSpec.describe "Search", :js, with_settings: { per_page_options: "5" } dolet!(:searched_for_project) { create(:project, name: "Searched for project") }let!(:other_project) { create(:project, name: "Other project") }- context "when globally" do+ subject do+ select_autocomplete(page.find(".top-menu-search--input"),+ query:,+ select_text: "In all projects ↵",+ wait_dropdown_open: false)++ within ".global-search--tabs" do+ click_on "Projects"+ end+ end++ shared_examples "finds the project" doit "finds the project" do- select_autocomplete(page.find(".top-menu-search--input"),- query: "Searched",- select_text: "In all projects ↵",- wait_dropdown_open: false)+ subject+ expect(page)+ .to have_link(searched_for_project.name)- within ".global-search--tabs" do- click_on "Projects"- end+ expect(page)+ .to have_no_link(other_project.name)+ end+ end+ shared_examples "does not find the project" do+ it "does not find the project" do+ subjectexpect(page)- .to have_link(searched_for_project.name)+ .to have_no_link(searched_for_project.name)expect(page).to have_no_link(other_project.name)end+ end++ context "when globally" do+ let(:query) { "Searched" }++ it_behaves_like "finds the project"describe "searching for list project custom field" do- let(:project_list_cf) do+ let(:possible_values) { %w[Value1 Value2 Value3] }+ let!(:project_list_cf) docreate(:list_project_custom_field,multi_value: true,projects: [searched_for_project],- possible_values: %w[Value1 Value2 Value3],+ possible_values:,searchable:).tap do |cf|searched_for_project.update(custom_field_values: { cf.id => cf.possible_values.pluck(:id).first(2) })endend- let(:first_selected_value) { project_list_cf.possible_values.pick(:value) }+ let(:query) { project_list_cf.possible_values.pick(:value) }- before do- select_autocomplete(page.find(".top-menu-search--input"),- query: first_selected_value,- select_text: "In all projects ↵",- wait_dropdown_open: false)-- within ".global-search--tabs" do- click_on "Projects"- end- end-- it "finds the project" do- expect(page)- .to have_link(searched_for_project.name)-- expect(page)- .to have_no_link(other_project.name)- end+ it_behaves_like "finds the project"context "when searchable is false" dolet(:searchable) { false }- it "does not find the project" do- expect(page)- .to have_no_link(searched_for_project.name)-- expect(page)- .to have_no_link(other_project.name)- end+ it_behaves_like "does not find the project"endcontext "when not enabled for project" dobefore do- searched_for_project.project_custom_field_project_mappings.destroy_all+ ProjectCustomFieldProjectMapping.destroy_allend- it "does not find the project" do- expect(page)- .to have_no_link(searched_for_project.name)+ it_behaves_like "does not find the project"+ end- expect(page)- .to have_no_link(other_project.name)- end+ context "when using % in the query string the escaping works correcly and" do+ let(:query) { "%#{project_list_cf.possible_values.pick(:value)}" }++ it_behaves_like "does not find the project"+ end++ context "when the value contains a % character" do+ let(:possible_values) { %w[%Value1 Value2 Value3] }++ it_behaves_like "finds the project"endendend