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:
parent
65b6d12b44
commit
7fda5d3273
|
@ -292,7 +292,13 @@ local force_ignore = {
|
||||||
function rules.high_priority_properties.tag(c, value, props)
|
function rules.high_priority_properties.tag(c, value, props)
|
||||||
if value then
|
if value then
|
||||||
if type(value) == "string" then
|
if type(value) == "string" then
|
||||||
|
local name = value
|
||||||
value = atag.find_by_name(c.screen, 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
|
end
|
||||||
|
|
||||||
-- In case the tag has been forced to another screen, move the client
|
-- In case the tag has been forced to another screen, move the client
|
||||||
|
|
|
@ -5,6 +5,7 @@ local test_client = require("_client")
|
||||||
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
|
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
|
||||||
|
|
||||||
local callback_called = false
|
local callback_called = false
|
||||||
|
local message_printed = false
|
||||||
|
|
||||||
-- Magic table to store tests
|
-- Magic table to store tests
|
||||||
local tests = {}
|
local tests = {}
|
||||||
|
@ -46,9 +47,16 @@ local function get_client_by_class(class)
|
||||||
end
|
end
|
||||||
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 callback and floating
|
||||||
test_rule {
|
test_rule {
|
||||||
properties = { floating = true },
|
properties = { floating = true, tag = "does_not_exist" },
|
||||||
callback = function(c)
|
callback = function(c)
|
||||||
assert(type(c) == "client")
|
assert(type(c) == "client")
|
||||||
callback_called = true
|
callback_called = true
|
||||||
|
@ -57,6 +65,10 @@ test_rule {
|
||||||
-- Test if callbacks works
|
-- Test if callbacks works
|
||||||
assert(callback_called)
|
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
|
-- Make sure "smart" dynamic properties are applied
|
||||||
assert(get_client_by_class(class).floating)
|
assert(get_client_by_class(class).floating)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue