California lawmakers have vowed to close a loophole that allowed a man's rape conviction to be overturned because his victim was not married.
An arcane state law says a person who gets consent for sex by pretending to be someone else is guilty of rape only if posing as the victim's spouse.
Julio Morales was initially convicted of rape after pretending to be the unmarried victim's boyfriend.
A similar loophole has already been closed in the state of Idaho.
In the California case from four years ago, Morales went into a room and had sex with an 18-year-old woman after her boyfriend, whom she had fallen asleep beside, had left.
She awoke to find she was having sex with Morales, a friend of her brother.
Posed as boyfriend, not a husband
She only realised the man in her bed was not her partner when a ray of light from outside the room flashed across his face.
Defence lawyers argued that Morales believed the sex was consensual because the victim had responded to his kisses and caresses. But he was sentenced to three years in prison.
In its ruling on Wednesday, the California appeal court reluctantly decided that Morales was not guilty of rape, because he was pretending to be the woman's boyfriend and not her husband.
A law dating back to 1872 makes it a crime for a man to have sex with a woman while posing as her husband, but not as a boyfriend.
Judge Thomas Willhite wrote in the court's decision: "Has the man committed rape? Because of historical anomalies in the law and the statutory definition of rape, the answer is no, even though, if the woman had been married and the man had impersonated her husband, the answer would be yes."
A similar law in the state of Idaho prevented an unmarried woman from pressing rape charges three years ago after she was tricked into sex with a stranger by her then-boyfriend.
Idaho's law was amended to cover all women in 2011.
State politician Katcho Achadjian said on Friday that he would introduce a bill.
"Californians are justifiably outraged by this court ruling, and it is important that the legislature join together to close whatever loopholes may exist in the law and uphold justice for rape victims," he said.
Assemblywoman Bonnie Lowenthal said she would back him.
"Allowing this [law] to stand in the 21st Century would be like applying horse and buggy standards to our freeways," she said in a statement, reported by the Los Angeles Times.