Skip to content

Commit

Permalink
Fix regex parsing (#799)
Browse files Browse the repository at this point in the history
Fixes #792
  • Loading branch information
bguidolim authored Aug 21, 2024
1 parent 28aee1b commit 1f9e7d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion PhoneNumberKit/MetadataParsing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public extension MetadataTerritory {
let possibleNationalPrefixForParsing: String? = try container.decodeIfPresent(String.self, forKey: .nationalPrefixForParsing)
let possibleNationalPrefix: String? = try container.decodeIfPresent(String.self, forKey: .nationalPrefix)
nationalPrefix = possibleNationalPrefix
nationalPrefixForParsing = (possibleNationalPrefixForParsing == nil && possibleNationalPrefix != nil) ? nationalPrefix : possibleNationalPrefixForParsing
let nationalPrefixForParsing = (possibleNationalPrefixForParsing == nil && possibleNationalPrefix != nil) ? nationalPrefix : possibleNationalPrefixForParsing
self.nationalPrefixForParsing = nationalPrefixForParsing != nil ? nationalPrefixForParsing!.replacingOccurrences(of: "\\", with: #"\\"#) : nil
nationalPrefixFormattingRule = try container.decodeIfPresent(String.self, forKey: .nationalPrefixFormattingRule)
let availableFormats = try? container.nestedContainer(keyedBy: CodingKeys.self, forKey: .availableFormats)
let temporaryFormatList: [MetadataPhoneNumberFormat] = availableFormats?.decodeArrayOrObject(forKey: .numberFormats) ?? [MetadataPhoneNumberFormat]()
Expand Down
6 changes: 6 additions & 0 deletions PhoneNumberKitTests/PartialFormatterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -692,5 +692,11 @@ final class PartialFormatterTests: XCTestCase {
_ = partialFormatter.formatPartial("+7")
XCTAssertEqual(partialFormatter.currentRegion, "RU")
}

func testJerseyPhoneNumberWithoutPrefix() {
let partialFormatter = PartialFormatter(utility: utility, defaultRegion: "JE", withPrefix: false)
let testNumber = "078297"
XCTAssertEqual(partialFormatter.formatPartial(testNumber), "7829 7")
}
}
#endif

0 comments on commit 1f9e7d7

Please sign in to comment.