awful.rules: Handle non-existing tags

If a tag is specified by name, but no such tags exist, awful.rules would
cause an error (attempt to index a nil value). Fix this and add a test
for this case.

Fixes: https://github.com/awesomeWM/awesome/issues/2087
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2017-10-31 13:23:12 +01:00
parent 65b6d12b44
commit 7fda5d3273
2 changed files with 19 additions and 1 deletions

View File

@ -292,7 +292,13 @@ local force_ignore = {
function rules.high_priority_properties.tag(c, value, props)
if value then
if type(value) == "string" then
local name = value
value = atag.find_by_name(c.screen, value)
if not value then
require("gears.debug").print_error("awful.rules-rule specified "
.. "tag = '" .. name .. "', but no such tag exists")
return
end
end
-- In case the tag has been forced to another screen, move the client

View File

@ -5,6 +5,7 @@ local test_client = require("_client")
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
local callback_called = false
local message_printed = false
-- Magic table to store tests
local tests = {}
@ -46,9 +47,16 @@ local function get_client_by_class(class)
end
end
local orig_error = gears.debug.print_error
function gears.debug.print_error(msg)
assert(not message_printed, msg)
assert(msg:find("specified tag = 'does_not_exist', but no such tag exists"), msg)
message_printed = true
end
-- Test callback and floating
test_rule {
properties = { floating = true },
properties = { floating = true, tag = "does_not_exist" },
callback = function(c)
assert(type(c) == "client")
callback_called = true
@ -57,6 +65,10 @@ test_rule {
-- Test if callbacks works
assert(callback_called)
-- Test that the "does_not_exist"-tag caused an error
assert(message_printed)
gears.debug.print_error = orig_error
-- Make sure "smart" dynamic properties are applied
assert(get_client_by_class(class).floating)