In a paper I am writing I need to show that a certain real-valued function $f\in C^0(B_1)$ belongs to the Sobolev space $W^{1,2}(B_1)$ ($B_1$ is the unit ball). So far I have been able to show that the weak derivative $Df$ exists on the open set $B_1\setminus \{f=0\}$ and $Df \mathbb{1}_{f\neq 0}\in L^2(B_1)$, so now I only have to deal with the set $\{f=0\}$. I suspect that it shouldn't matter and that the weak differential $Df$ exists on all $B_1$ and is equal to $Df \mathbb{1}_{f\neq 0}$ a.e., but I am having troubles proving it formally. Any help/hint is appreciated.

EDIT: The question makes sense under the weaker assumptions that $f\in L^2(B_1)\cap W^{1,2}(B_1\setminus K)$ where $K$ is a compact set on which $f=0$ a.e. Both the comment of Giorgio Metafune and the answer by Nate River are still true in this generalised setting.