الآية رقم (267) - يَا أَيُّهَا الَّذِينَ آمَنُواْ أَنفِقُواْ مِن طَيِّبَاتِ مَا كَسَبْتُمْ وَمِمَّا أَخْرَجْنَا لَكُم مِّنَ الأَرْضِ وَلاَ تَيَمَّمُواْ الْخَبِيثَ مِنْهُ تُنفِقُونَ وَلَسْتُم بِآخِذِيهِ إِلاَّ أَن تُغْمِضُواْ فِيهِ وَاعْلَمُواْ أَنَّ اللّهَ غَنِيٌّ حَمِيدٌ

(267) - (O you who have believed, spend from the good things which you have earned and from that which We have produced for you from the earth. And do not aim toward the defective therefrom, spending [from that] while you would not take it [yourself] except with closed eyes. And know that Allah is Free of need and Praiseworthy.)

Here is another condition for spending: {spend from the good things which you have earned} Never steal and give away. In this context, a poet once said:

‘Condemned is she,

Who wants to do the good

From what to her genitals they pay,

Neither she enjoys nor gives away,’

Spending should be as legislated by the Almighty in order to get accepted by Him.

Reason of revelation:

Sahl Bin Haneef narrated that people used to pick the worst of their fruits to be given away as a charity. Therefore, (And do not aim toward the defective therefrom, spending [from that] while you would not take it [yourself]) was revealed.

The verse should be generalized in terms of meaning rather than considered to be for a specific reason. So, spend what you love when you want to do that.

 {لَن تَنَالُوا الْبِرَّ حَتَّىٰ تُنفِقُوا مِمَّا تُحِبُّونَ}

(Never will you attain the good [reward] until you spend [in the way of Allah] from that which you love.) (Aal-Imran: 92)

So, it should be from what you love not the bad or the rotten.