From b358b88e356d6ecfc251bb7a0989a679577c4503 Mon Sep 17 00:00:00 2001 From: Narcis Beleuzu Date: Sun, 14 Oct 2018 12:01:37 +0300 Subject: [PATCH] Backed out changeset 31313cac4517 (bug 1485105) for causing Bug1498071. a=backout --- .../test/browser_formdata_xpath.js | 2 +- .../satchel/test/test_form_submission.html | 8 ++-- toolkit/modules/CreditCard.jsm | 10 ++-- .../modules/tests/xpcshell/test_CreditCard.js | 46 ++++--------------- 4 files changed, 19 insertions(+), 47 deletions(-) diff --git a/browser/components/sessionstore/test/browser_formdata_xpath.js b/browser/components/sessionstore/test/browser_formdata_xpath.js index a3c74e96b2da..7f6498624ee7 100644 --- a/browser/components/sessionstore/test/browser_formdata_xpath.js +++ b/browser/components/sessionstore/test/browser_formdata_xpath.js @@ -21,7 +21,7 @@ const FILE1 = createFilePath("346337_test1.file"); const FILE2 = createFilePath("346337_test2.file"); const FIELDS = { - "//input[@name='input']": Date.now().toString(16), + "//input[@name='input']": Date.now().toString(), "//input[@name='spaced 1']": Math.random().toString(), "//input[3]": "three", "//input[@type='checkbox']": true, diff --git a/toolkit/components/satchel/test/test_form_submission.html b/toolkit/components/satchel/test/test_form_submission.html index 33a367dba1c9..297462cf6e1f 100644 --- a/toolkit/components/satchel/test/test_form_submission.html +++ b/toolkit/components/satchel/test/test_form_submission.html @@ -124,7 +124,7 @@ - +
@@ -322,7 +322,7 @@ function startTest() { for (let i = 0; i != testData.length; i++) { $_(16, "test" + (i + 1)).value = testData[i]; } - $_(17, "test1").value = "6799990100000000019"; + $_(17, "test1").value = "001064088"; $_(18, "test1").value = "0000-0000-0080-4609"; $_(19, "test1").value = "0000 0000 0222 331"; $_(20, "test1").value = "dontSaveThis"; @@ -334,7 +334,7 @@ function startTest() { $_(103, "test3").value = "savedValue"; $_(104, "test4").value = " trimTrailingAndLeadingSpace "; $_(105, "test5").value = "\t trimTrailingAndLeadingWhitespace\t "; - $_(106, "test6").value = "55555555555544445553"; // passes luhn but too long + $_(106, "test6").value = "00000000109181"; testData = ccNumbers.invalid16; for (let i = 0; i != testData.length; i++) { @@ -412,7 +412,7 @@ function checkSubmit(formNum) { "checking saved value is trimmed on both sides"); break; case 106: - checkForSave("test6", "55555555555544445553", "checking saved value"); + checkForSave("test6", "00000000109181", "checking saved value"); break; case 107: for (let i = 0; i != ccNumbers.invalid16.length; i++) { diff --git a/toolkit/modules/CreditCard.jsm b/toolkit/modules/CreditCard.jsm index 5ac8a0ac9f7a..2cc30d599b7b 100644 --- a/toolkit/modules/CreditCard.jsm +++ b/toolkit/modules/CreditCard.jsm @@ -108,9 +108,9 @@ class CreditCard { if (value) { let normalizedNumber = value.replace(/[-\s]/g, ""); // Based on the information on wiki[1], the shortest valid length should be - // 12 digits (Maestro). - // [1] https://en.wikipedia.org/wiki/Payment_card_number - normalizedNumber = normalizedNumber.match(/^\d{12,}$/) ? + // 9 digits (Canadian SIN). + // [1] https://en.wikipedia.org/wiki/Social_Insurance_Number + normalizedNumber = normalizedNumber.match(/^\d{9,}$/) ? normalizedNumber : null; this._number = normalizedNumber; } @@ -126,8 +126,6 @@ class CreditCard { // Implements the Luhn checksum algorithm as described at // http://wikipedia.org/wiki/Luhn_algorithm - // Number digit lengths vary with network, but should fall within 12-19 range. [2] - // More details at https://en.wikipedia.org/wiki/Payment_card_number isValidNumber() { if (!this._number) { return false; @@ -137,7 +135,7 @@ class CreditCard { let number = this._number.replace(/[\-\s]/g, ""); let len = number.length; - if (len < 12 || len > 19) { + if (len != 9 && len != 15 && len != 16) { return false; } diff --git a/toolkit/modules/tests/xpcshell/test_CreditCard.js b/toolkit/modules/tests/xpcshell/test_CreditCard.js index 71a029614c79..70e3747f69bc 100644 --- a/toolkit/modules/tests/xpcshell/test_CreditCard.js +++ b/toolkit/modules/tests/xpcshell/test_CreditCard.js @@ -15,42 +15,20 @@ add_task(function isValidNumber() { } testValid("0000000000000000", true); - - testValid("41111111112", false); // passes Luhn but too short - testValid("4111-1111-112", false); // passes Luhn but too short - testValid("55555555555544440018", false); // passes Luhn but too long - testValid("5555 5555 5555 4444 0018", false); // passes Luhn but too long - testValid("4929001587121045", true); testValid("5103059495477870", true); testValid("6011029476355493", true); testValid("3589993783099582", true); testValid("5415425865751454", true); - - testValid("378282246310005", true); // American Express test number - testValid("371449635398431", true); // American Express test number - testValid("378734493671000", true); // American Express Corporate test number - testValid("5610591081018250", true); // Australian BankCard test number - testValid("6759649826438453", true); // Maestro test number - testValid("6799990100000000019", true); // 19 digit Maestro test number - testValid("6799-9901-0000-0000019", true); // 19 digit Maestro test number - testValid("30569309025904", true); // 14 digit Diners Club test number - testValid("38520000023237", true); // 14 digit Diners Club test number - testValid("6011111111111117", true); // Discover test number - testValid("6011000990139424", true); // Discover test number - testValid("3530111333300000", true); // JCB test number - testValid("3566002020360505", true); // JCB test number - testValid("3532596776688495393", true); // 19-digit JCB number. JCB, Discover, Maestro could have 16-19 digits - testValid("3532 5967 7668 8495393", true); // 19-digit JCB number. JCB, Discover, Maestro could have 16-19 digits - testValid("5555555555554444", true); // MasterCard test number - testValid("5105105105105100", true); // MasterCard test number - testValid("2221000000000009", true); // 2-series MasterCard test number - testValid("4111111111111111", true); // Visa test number - testValid("4012888888881881", true); // Visa test number - testValid("4222222222222", true); // 13 digit Visa test number - testValid("4222 2222 22222", true); // 13 digit Visa test number - testValid("4035 5010 0000 0008", true); // Visadebit/Cartebancaire test number - + if (CreditCard.isValidNumber("30190729470495")) { + ok(false, "todo: 14-digit numbers (Diners Club) aren't supported by isValidNumber yet"); + } + if (CreditCard.isValidNumber("36333851788250")) { + ok(false, "todo: 14-digit numbers (Diners Club) aren't supported by isValidNumber yet"); + } + if (CreditCard.isValidNumber("3532596776688495393")) { + ok(false, "todo: 19-digit numbers (JCB, Discover, Maestro) could have 16-19 digits"); + } testValid("5038146897157463", true); testValid("4026313395502338", true); testValid("6387060366272981", true); @@ -77,8 +55,7 @@ add_task(function isValidNumber() { testValid("0000-0000-0080-4609", true); testValid("0000 0000 0222 331", true); testValid("344060747836806", true); - testValid("001064088", false); // too short - testValid("00-10-64-088", false); // still too short + testValid("001064088", true); testValid("4929001587121046", false); testValid("5103059495477876", false); testValid("6011029476355494", false); @@ -140,7 +117,6 @@ add_task(function test_maskNumber() { testMask("3589993783099582", "**** 9582"); testMask("5415425865751454", "**** 1454"); testMask("344060747836806", "**** 6806"); - testMask("6799990100000000019", "**** 0019"); Assert.throws(() => (new CreditCard({number: "1234"})).maskedNumber, /Invalid credit card number/, "Four or less numbers should throw when retrieving the maskedNumber"); @@ -159,8 +135,6 @@ add_task(function test_longMaskedNumber() { testMask("3589993783099582", "************9582"); testMask("5415425865751454", "************1454"); testMask("344060747836806", "***********6806"); - testMask("6799990100000000019", "***************0019"); - Assert.throws(() => (new CreditCard({number: "1234"})).longMaskedNumber, /Invalid credit card number/, "Four or less numbers should throw when retrieving the maskedNumber");