Fixes #275: a colon (amongst other invalid chars) is replaced by valid characters. Also a NPE is prevents, related to issue #294.