diff --git a/PhoneNumberKit/MetadataParsing.swift b/PhoneNumberKit/MetadataParsing.swift index 4b837539..2c3d6018 100644 --- a/PhoneNumberKit/MetadataParsing.swift +++ b/PhoneNumberKit/MetadataParsing.swift @@ -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]() diff --git a/PhoneNumberKitTests/PartialFormatterTests.swift b/PhoneNumberKitTests/PartialFormatterTests.swift index 46c012a5..e1f7bf91 100644 --- a/PhoneNumberKitTests/PartialFormatterTests.swift +++ b/PhoneNumberKitTests/PartialFormatterTests.swift @@ -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