Bug 821876 - Fix ParseNumber so that it accepts a null defaultRegion. r=gal, a=blocking-basecamp
authorGregor Wagner <anygregor@gmail.com>
Mon, 17 Dec 2012 18:20:31 -0800
changeset 118979 63d5c5092a908e472a05e3f192eacc7ab4d42ace
parent 118978 bd0d69dd3fb7cda0dd502f7608b843b17ed6f758
child 118980 93150917eff6f1121296789c6293b39601b71b49
push id3007
push userryanvm@gmail.com
push dateTue, 18 Dec 2012 23:10:59 +0000
treeherdermozilla-aurora@63d5c5092a90 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgal, blocking-basecamp
bugs821876
milestone19.0a2
Bug 821876 - Fix ParseNumber so that it accepts a null defaultRegion. r=gal, a=blocking-basecamp
dom/phonenumberutils/PhoneNumber.jsm
dom/phonenumberutils/tests/Makefile.in
dom/phonenumberutils/tests/test_phonenumberutils.xul
--- a/dom/phonenumberutils/PhoneNumber.jsm
+++ b/dom/phonenumberutils/PhoneNumber.jsm
@@ -295,16 +295,20 @@ this.PhoneNumber = (function (dataBase) 
   // Parse a number and transform it into the national format, removing any
   // international dial prefixes and country codes.
   function ParseNumber(number, defaultRegion) {
     var ret;
 
     // Remove formating characters and whitespace.
     number = NormalizeNumber(number);
 
+    // If there is no defaultRegion, we can't parse international access codes.
+    if (!defaultRegion && number[0] !== '+')
+      return null;
+
     // Detect and strip leading '+'.
     if (number[0] === '+')
       return ParseInternationalNumber(number.replace(PLUS_CHARS, ""));
 
     // Lookup the meta data for the given region.
     var md = FindMetaDataForRegion(defaultRegion.toUpperCase());
 
     // See if the number starts with an international prefix, and if the
--- a/dom/phonenumberutils/tests/Makefile.in
+++ b/dom/phonenumberutils/tests/Makefile.in
@@ -11,11 +11,12 @@ relativesrcdir   = @relativesrcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 DIRS = \
   $(NULL)
 
 MOCHITEST_CHROME_FILES = \
   test_phonenumber.xul \
+  test_phonenumberutils.xul \
   $(NULL)
 
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/dom/phonenumberutils/tests/test_phonenumberutils.xul
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+
+<!-- Any copyright is dedicated to the Public Domain.
+   - http://creativecommons.org/publicdomain/zero/1.0/ -->
+
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
+
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        title="Mozilla Bug 781379">
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+  <script type="application/javascript" src="head.js"/>
+  <!-- test results are displayed in the html:body -->
+  <body xmlns="http://www.w3.org/1999/xhtml">
+  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=809213"
+     target="_blank">Mozilla Bug 809213</a>
+  </body>
+
+<script type="application/javascript;version=1.8">
+
+"use strict";
+
+Components.utils.import("resource://gre/modules/PhoneNumberUtils.jsm");
+
+function CantParseWithMcc(dial, mcc) {
+  var result = PhoneNumberUtils.parseWithMCC(dial, mcc);
+  if (result) {
+  	ok(false, "Shouldn't parse!\n");
+    print("expected: does not parse");
+    print("got: " + dial + " " + mcc);
+  } else {
+    ok(true, "Parses");
+  }
+}
+
+// Unknown mcc
+CantParseWithMcc("1234", 123);
+
+</script>
+</window>