Bug 821876 - Fix ParseNumber so that it accepts a null defaultRegion. r=gal
authorGregor Wagner <anygregor@gmail.com>
Mon, 17 Dec 2012 18:20:31 -0800
changeset 125475 79a8d91ba1cb87464ca887e3c016b8945e3a9977
parent 125474 d65f28340dd95357d07e15f94fa2fc67d695e5b0
child 125476 55b179e8c9805bf3d0d3d59e1f87f867a9e7b92e
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgal
bugs821876
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 821876 - Fix ParseNumber so that it accepts a null defaultRegion. r=gal
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
@@ -296,16 +296,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>