Recovering exponential accuracy in spectral methods involving piecewise smooth functions with unbounded derivative singularities