Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regex parsing #799

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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