I have a previous post stating that a worm on fruits and vegetables is a sign of commodity safety. It means the farmer who grew it never used pesticides of any kind. The worm was very lucky. He have never eaten any poisonous substance. If the worm survived on veggie, the more you will stay unharmed.
Notice the market vendors who sell ready mix raw veggies, e.g. ready mix lumpiang sariwa and chopsuey. Most of the materials they are using are rejects, vegetables with cracks, worms and and bruises. They are trimming off the ugly part and getting the good.
However, the worm on fruit or vegetable does not always imply product safety. It may also mean that fruit is spoiled and should not be eaten. The perfect example is guava. The unripe to rare ripe guava is hard, hard enough to resist insect and worm bites. Worm on or in hard guava is very unlikely, unless a hybrid which can cut to hard skin exist. As the guava ripens, the skin becomes soft and insect can cut through it easily.
Worms in ripe guava are not easy to detect. They feed inside. The thick skin is harder than pulp. Worms prefer the softer part. Examine every fruit carefully. Avoid items with small holes. Holes = worms. The thick rind protects the inside pulp. An opening made by the worm entry hasten the spoilage.