Republican David McCormick was dealt a legal victory Thursday when a judge ruled that counties must count ballots that arrived by mail in undated envelopes in the primary race for U.S. Senate in Pennsylvania.

The ruling was made in the Pennsylvania Commonwealth Court after McCormick filed a lawsuit arguing the ballots should be counted. The ruling could potentially benefit McCormick in a race that remains too close to call, as McCormick has performed better with mail-in ballots than his opponent, Dr. Mehmet Oz.

Oz currently leads McCormick by fewer than 1,000 votes out of more than 1.3 million cast following the May 17 primary. That narrow margin automatically triggered a recount, which is now underway, even while the initial unofficial results of the race are still being finalized.

Judge Renée Cohn Jubelirer, who was elected to the court as a Republican in 2001, wrote in her ruling about the ballots in question that “no compelling reason” existed to disqualify ballots that arrived in undated envelopes, according to the Philadelphia Inquirer.

“The absence of a handwritten date on the exterior envelope could be considered a ‘minor irregularity’ without a compelling reason that justifies the disenfranchisement of otherwise eligible voters,” Jubelirer wrote.

About 800 undated Republican primary ballots remained in the balance when this court decision was made, per the Inquirer.

Oz, who prematurely declared himself the “presumptive” Republican nominee for the Senate race last week, has been behind McCormick in mail-in ballots and has remained opposed to counting the undated ones. Oz argued McCormick is “following the Democrats’ playbook” by urging for such ballots to be deemed valid.

The court’s decision Thursday was therefore a blow to Oz, as well as to the Republican National Committee (RNC) and the Pennsylvania Republican Party, groups that intervened against McCormick in his lawsuit.

The RNC in particular surprised some Republicans after siding with Oz in the case rather than remaining neutral as it traditionally has in primary races, but chairwoman Ronna McDaniel contended the organization has kept its neutrality.

“Undated ballots should not be counted in Pennsylvania according to their state law. That is what this is about. This is about November, not this primary,” McDaniel told Breitbart News last week. “We absolutely did not intervene in this primary. The amount of undated ballots that are out there, we don’t know what that is. It certainly should not lead to a slippery slope that Democrats can use to upend election integrity in November.”

Oz could appeal the court’s decision that counties count the ballots to the Pennsylvania Supreme Court, but in any case, the celebrity doctor is still maintaining his slim lead in the race as recount results trickle in and as McCormick is “running out of runway,” according to the Inquirer.

Democrats meanwhile appear to be treating the race as too close to call. The campaign arm for Senate Democrats, the Democratic Senatorial Campaign Committee (DSCC), is circulating two draft advertisements, shared by Axios, that target each of the candidates in preparation for the general election battleground race.

“Democrats are wasting no time” attacking their two potential Republican opponents, a DSCC spokesperson told the outlet.

Write to Ashley Oliver at aoliver@breitbart.com. Follow her on Twitter at @asholiver.