There is a similar story being told but no confirmation it is true.
Even scholars say it cannot be true.
It says that some Jewish man asked Ibrahim Ibn Adham: "which is better? Your beard or this dog's tail?"
The calm answer was: "if I will go to heaven it means my beard is better. Otherwise, the dog's tail is better".
There is criticisms on this story and disagreement. Not sure if this the one you are looking for.
However, the Quran in surat AlForqan aya 63 says something similar in meaning of what you are looking for. Not exactly. Please refer to it and to the tafseer.
The text in Arabic as I found it from some site:
يهودي معه كلب -واليهود لطالما استفزوا المسلمين يريدون أن يوقعوهم في شَرَكِهم- يمر على إبراهيم بن أدهم عليه رحمة الله ذلكم المؤمن، فيقول له: ألحيتك -يا إبراهيم - أطهر من ذنب هذا الكلب، أم ذنب الكلب أطهر من لحيتك؟
فما كان منه إلا أن قال -بهدوء المؤمن الواثق بموعود الله عز وجل-: إن كانت في الجنة فهي أطهر من ذنب كلبك، وإن كانت في النار لذنب كلبك أطهر منها.