(AP) — A Pennsylvania judge has ordered three Republican-controlled counties to add about 800 contested mail-in ballots to the results of the May election, ruling in a legal dispute that stalled statewide certification of the primary results for governor and U.S. Senate.

The Republican judge sided Friday with the Democratic governor in a lawsuit over whether mail-in ballots that lack handwritten dates on their return envelopes should be counted. The suit is the latest in a series of legal battles over the state’s 2019 election law, which greatly expanded mail-in voting.

Get daily news, weather, breaking news and alerts straight to your inbox! Sign up for the abc27 newsletters here

The law requires voters to date the envelopes. But Commonwealth Court President Judge Renee Cohn Jubelirer agreed with Gov. Tom Wolf’s administration that the lack of a date was a minor irregularity and should not result in those voters’ disenfranchisement.

The 2019 law eliminated straight-party voting — a provision favored by GOP lawmakers — but also gave Democrats a broad expansion of mail-in voting. Since the pandemic, Pennsylvania Democrats have voted by mail in far greater numbers than Republicans.

Berks, Fayette and Lancaster counties were ordered to count the undated mail-in ballots, and the judge gave the counties a Wednesday deadline to certify their primary election results — including the updated ballots — and report back to state election officials.

Get severe weather alerts with newsletters and push alerts from the abc27 Weather Team!

The Pennsylvania Department of State, which oversees elections, said that election results from the three counties would allow it to certify the results of the May primary, including for governor and Senate.

“We believe this ruling means that counties must henceforth include undated ballots in the totals they submit to the Department of State for certification,” said Amy Gulli, the department’s spokesperson.

The ruling came more than a month after the Wolf administration filed suit against the counties’ election boards to force them to count the undated ballots and certify their results.

Berks County is reviewing the decision and has not made a decision on an appeal, said spokesperson Stephanie Weaver. The Lancaster County board of commissioners declined comment. An email was sent to Fayette County officials seeking comment.

Get the latest Pennsylvania politics and election news with abc27 newsletters

In Friday’s ruling, Cohn Jubelirer noted the state Legislature did not expressly state that ballots lacking a handwritten date on the exterior envelope should be rejected. But other sections of the election law do require certain defective ballots to be invalidated, such as those that reveal a voter’s identifying information, she wrote.

“The dating provisions at issue do not expressly provide that such ballots should not be counted, unlike other provisions of the Election Code,” the judge wrote. “When certain provisions of the Election Code do not expressly provide for a consequence of noncompliance, the courts have found that, without something more, such as fear of fraud, the ballot should not be invalidated.”

The 2019 election law requires voters to write a date next to their signature on the outside of mail-in return envelopes. But the handwritten dates do not determine whether voters are eligible or if they cast their ballots on time.

Get traffic alerts from the abc27 mobile app for the latest local delays and road closures

Cohn Jubelirer’s decision said the requirement that voters date the return envelopes of their ballots had no obvious purpose.

After filing suit against the three counties, state officials learned that a fourth county, Butler, failed to include undated mail-in ballots in the election results it certified to the state.

The Wolf administration chose not to add Butler County to its lawsuit because the state’s top elections official had already certified the county’s results and “balanced the need to have accurate results with the need to have finality in these already-certified elections,” the judge wrote.