Indeed. If two (measurable) functions coincide except on a set of measure zero, then each one is as legitimate as the other to be the density of the probability distribution of a given random variable.
For example, consider the Borel function $f$ defined on $\mathbb R$ by $f(x)=1$ for every irrational $x$ in $(0,1)$ and $f(x)=0$ otherwise. For every random variable $X$ uniformly distributed on $[0,1]$ and every Borel subset $B$ of $\mathbb R$, $\mathrm P(X\in B)=\int\limits_Bf(x)\mathrm dx$. Since this is how the density of the probability distribution of $X$ is defined, the function $f$ is indeed a density for the uniform distribution on $[0,1]$, as suitable as the functions $\mathbf 1_{[0,1]}$ or $\mathbf 1_{(0,1)}$ (of course, the latter are more common choices).