diff --git a/app/logical/bulk_update_request_processor.rb b/app/logical/bulk_update_request_processor.rb index 8235939a6..741e8f38b 100644 --- a/app/logical/bulk_update_request_processor.rb +++ b/app/logical/bulk_update_request_processor.rb @@ -116,11 +116,10 @@ class BulkUpdateRequestProcessor end when :mass_update - lhs = PostQuery.new(args[0]) - rhs = PostQuery.new(args[1]) + query = PostQuery.new(args[0]) - if lhs.is_single_tag? && rhs.is_single_tag? - errors.add(:base, "Can't mass update #{args[0]} -> #{args[1]} (use an alias or a rename instead for tag moves)") + if query.is_null_search? + errors.add(:base, "Can't mass update #{args[0]} -> #{args[1]} (the search `#{args[0]}` has a syntax error)") end when :nuke diff --git a/app/logical/post_query.rb b/app/logical/post_query.rb index 54b8f59f2..73fbd30ae 100644 --- a/app/logical/post_query.rb +++ b/app/logical/post_query.rb @@ -16,6 +16,16 @@ class PostQuery Tag.where(name: tag_names) end + # True if this search would return all posts (normally because the search is the empty string). + def is_empty_search? + ast.all? + end + + # True if this search would return nothing (normally because there was a syntax error). + def is_null_search? + ast.none? + end + def is_single_tag? ast.tag? end diff --git a/test/unit/bulk_update_request_test.rb b/test/unit/bulk_update_request_test.rb index f47c5305c..c498fcbda 100644 --- a/test/unit/bulk_update_request_test.rb +++ b/test/unit/bulk_update_request_test.rb @@ -339,11 +339,11 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase assert_equal("approved", @bur.reload.status) end - should "not allow mass update for simple A -> B moves" do - @bur = build(:bulk_update_request, script: "mass update bunny -> rabbit") + should "not allow invalid searches in mass updates" do + @bur = build(:bulk_update_request, script: "mass update (foo -> bar") assert_equal(false, @bur.valid?) - assert_equal(["Can't mass update bunny -> rabbit (use an alias or a rename instead for tag moves)"], @bur.errors.full_messages) + assert_equal(["Can't mass update (foo -> bar (the search `(foo` has a syntax error)"], @bur.errors.full_messages) end end