Commits

Anonymous committed 83698c0

Stop modifying metadata in formatInOriginalFormat().

Bug: http://code.google.com/p/libphonenumber/issues/detail?id=91
Review URL: http://codereview.appspot.com/5573043

  • Participants
  • Parent commits 4349441
  • Branches default

Comments (0)

Files changed (2)

File java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java

           break;
         }
         // Otherwise, we need to remove the national prefix from our output.
-        formatRule.clearNationalPrefixFormattingRule();
+        NumberFormat numFormatCopy = new NumberFormat();
+        numFormatCopy.mergeFrom(formatRule);
+        numFormatCopy.clearNationalPrefixFormattingRule();
         List<NumberFormat> numberFormats = new ArrayList<NumberFormat>(1);
-        numberFormats.add(formatRule);
+        numberFormats.add(numFormatCopy);
         formattedNumber = formatByPattern(number, PhoneNumberFormat.NATIONAL, numberFormats);
         break;
     }

File java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java

         phoneUtil.parseAndKeepRawInput("2087654321", RegionCode.GB);
     assertEquals("20 8765 4321",
         phoneUtil.formatInOriginalFormat(numberWithoutNationalPrefixGB, RegionCode.GB));
+    // Make sure no metadata is modified as a result of the previous function call.
+    assertEquals("(020) 8765 4321", phoneUtil.formatInOriginalFormat(number5, RegionCode.GB));
 
     PhoneNumber numberWithNationalPrefixMX =
         phoneUtil.parseAndKeepRawInput("013312345678", RegionCode.MX);