Check if we have a string before calling replace().

I've occasionally been getting this error:

> TRACE     task[k] = task[k].replace(unsafe, safe)
> TRACE AttributeError: 'int' object has no attribute 'replace'

Checking if `task[k]` is a string before calling replace fixes the problem.