If someone attacks a swarm with a single-target spell while it’s in a character’s space, is that character also affected by the spell?

My players have walked into a Spider Lair and fought their first group of Spiderlings, or effectively a Swarm of Spiders from the MM. I didn’t realize until after the encounter that they have a reach of 0 for their attack and that they can move through and stay on a space taken up by another creature (which occurred to me is the only way it can actually make its attack.) The party’s going to fight more next session.

What happens when a swarm is in a character’s space attacking them, and someone casts a single-target spell against that swarm such as Hellish Rebuke or Fire Bolt?
Since the swarm is invading that character’s space (we assume because they are swarming around them or over them), is the character also potentially affected by the spell?