None of the existing questions is exactly answering my question so I'm posting a new question, but feel free to refer me to some already answered question!
In Rudin Theorem 4.22, we know that
If $f$ is a continuous mapping of a metric space $X$ into a metric space $Y$, and $E$ is a connected subset of $X$, then $f(E)$ is connected.
In the proof, we started with consider $f(E) = A \cup B$, where $A$ and $B$ are nonempty separated subsets. Then put $G = E \cap f^{-1}(A)$ and $H = E \cap f^{-1}(B)$. Then Rudin is claiming that $E = G \cup H$. I'm a little suspicious about this. What if $f$ is non-surjective, then $f^{-1}(A) \cup f^{-1}(B)$ is only a proper subset of $E$? Is there a property of $f$ being continuous that forces $f$ to be 1-1?