Bug 1371568 - Add Chris O"Hara's validator.js library for string validation in the storage inspector r=pbro

MozReview-Commit-ID: 5HM5E8LBptT

--HG--
extra : rebase_source : 173e44be5ac3e5c2e5f5fc6a604427ddf4c41b9c
This commit is contained in:
Michael Ratcliffe 2017-06-06 13:31:48 +01:00
Родитель 16beecaaf1
Коммит a5660a9c4c
11 изменённых файлов: 6118 добавлений и 0 удалений

5
devtools/client/shared/vendor/moz.build поставляемый
Просмотреть файл

@ -3,6 +3,11 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
DIRS += [
'stringvalidator',
]
modules = []
modules += [
'immutable.js',

142
devtools/client/shared/vendor/stringvalidator/UPDATING.md поставляемый Normal file
Просмотреть файл

@ -0,0 +1,142 @@
# Updating this library
1. Replace the contents of validator.js with the contents of https://github.com/chriso/validator.js/blob/master/validator.js.
2. Add the following methods:
```
// see http://isrc.ifpi.org/en/isrc-standard/code-syntax
var isrc = /^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;
function isISRC(str) {
assertString(str);
return isrc.test(str);
}
```
```
var cultureCodes = new Set(["ar", "bg", "ca", "zh-Hans", "cs", "da", "de",
"el", "en", "es", "fi", "fr", "he", "hu", "is", "it", "ja", "ko", "nl", "no",
"pl", "pt", "rm", "ro", "ru", "hr", "sk", "sq", "sv", "th", "tr", "ur", "id",
"uk", "be", "sl", "et", "lv", "lt", "tg", "fa", "vi", "hy", "az", "eu", "hsb",
"mk", "tn", "xh", "zu", "af", "ka", "fo", "hi", "mt", "se", "ga", "ms", "kk",
"ky", "sw", "tk", "uz", "tt", "bn", "pa", "gu", "or", "ta", "te", "kn", "ml",
"as", "mr", "sa", "mn", "bo", "cy", "km", "lo", "gl", "kok", "syr", "si", "iu",
"am", "tzm", "ne", "fy", "ps", "fil", "dv", "ha", "yo", "quz", "nso", "ba", "lb",
"kl", "ig", "ii", "arn", "moh", "br", "ug", "mi", "oc", "co", "gsw", "sah",
"qut", "rw", "wo", "prs", "gd", "ar-SA", "bg-BG", "ca-ES", "zh-TW", "cs-CZ",
"da-DK", "de-DE", "el-GR", "en-US", "fi-FI", "fr-FR", "he-IL", "hu-HU", "is-IS",
"it-IT", "ja-JP", "ko-KR", "nl-NL", "nb-NO", "pl-PL", "pt-BR", "rm-CH", "ro-RO",
"ru-RU", "hr-HR", "sk-SK", "sq-AL", "sv-SE", "th-TH", "tr-TR", "ur-PK", "id-ID",
"uk-UA", "be-BY", "sl-SI", "et-EE", "lv-LV", "lt-LT", "tg-Cyrl-TJ", "fa-IR",
"vi-VN", "hy-AM", "az-Latn-AZ", "eu-ES", "hsb-DE", "mk-MK", "tn-ZA", "xh-ZA",
"zu-ZA", "af-ZA", "ka-GE", "fo-FO", "hi-IN", "mt-MT", "se-NO", "ms-MY", "kk-KZ",
"ky-KG", "sw-KE", "tk-TM", "uz-Latn-UZ", "tt-RU", "bn-IN", "pa-IN", "gu-IN",
"or-IN", "ta-IN", "te-IN", "kn-IN", "ml-IN", "as-IN", "mr-IN", "sa-IN", "mn-MN",
"bo-CN", "cy-GB", "km-KH", "lo-LA", "gl-ES", "kok-IN", "syr-SY", "si-LK",
"iu-Cans-CA", "am-ET", "ne-NP", "fy-NL", "ps-AF", "fil-PH", "dv-MV",
"ha-Latn-NG", "yo-NG", "quz-BO", "nso-ZA", "ba-RU", "lb-LU", "kl-GL", "ig-NG",
"ii-CN", "arn-CL", "moh-CA", "br-FR", "ug-CN", "mi-NZ", "oc-FR", "co-FR",
"gsw-FR", "sah-RU", "qut-GT", "rw-RW", "wo-SN", "prs-AF", "gd-GB", "ar-IQ",
"zh-CN", "de-CH", "en-GB", "es-MX", "fr-BE", "it-CH", "nl-BE", "nn-NO", "pt-PT",
"sr-Latn-CS", "sv-FI", "az-Cyrl-AZ", "dsb-DE", "se-SE", "ga-IE", "ms-BN",
"uz-Cyrl-UZ", "bn-BD", "mn-Mong-CN", "iu-Latn-CA", "tzm-Latn-DZ", "quz-EC",
"ar-EG", "zh-HK", "de-AT", "en-AU", "es-ES", "fr-CA", "sr-Cyrl-CS", "se-FI",
"quz-PE", "ar-LY", "zh-SG", "de-LU", "en-CA", "es-GT", "fr-CH", "hr-BA",
"smj-NO", "ar-DZ", "zh-MO", "de-LI", "en-NZ", "es-CR", "fr-LU", "bs-Latn-BA",
"smj-SE", "ar-MA", "en-IE", "es-PA", "fr-MC", "sr-Latn-BA", "sma-NO", "ar-TN",
"en-ZA", "es-DO", "sr-Cyrl-BA", "sma-SE", "ar-OM", "en-JM", "es-VE",
"bs-Cyrl-BA", "sms-FI", "ar-YE", "en-029", "es-CO", "sr-Latn-RS", "smn-FI",
"ar-SY", "en-BZ", "es-PE", "sr-Cyrl-RS", "ar-JO", "en-TT", "es-AR", "sr-Latn-ME",
"ar-LB", "en-ZW", "es-EC", "sr-Cyrl-ME", "ar-KW", "en-PH", "es-CL", "ar-AE",
"es-UY", "ar-BH", "es-PY", "ar-QA", "en-IN", "es-BO", "en-MY", "es-SV", "en-SG",
"es-HN", "es-NI", "es-PR", "es-US", "bs-Cyrl", "bs-Latn", "sr-Cyrl", "sr-Latn",
"smn", "az-Cyrl", "sms", "zh", "nn", "bs", "az-Latn", "sma", "uz-Cyrl",
"mn-Cyrl", "iu-Cans", "zh-Hant", "nb", "sr", "tg-Cyrl", "dsb", "smj", "uz-Latn",
"mn-Mong", "iu-Latn", "tzm-Latn", "ha-Latn", "zh-CHS", "zh-CHT"]);
function isRFC5646(str) {
assertString(str);
// According to the spec these codes are case sensitive so we can check the
// string directly.
return cultureCodes.has(str);
}
```
```
var semver = /^v?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$/i
function isSemVer(str) {
assertString(str);
return semver.test(str);
}
```
```
var rgbcolor = /^rgb?\(\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])\s*,\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])\s*,\s*(0|[1-9]\d?|1\d\d?|2[0-4]\d|25[0-5])\s*\)$/i
function isRGBColor(str) {
assertString(str);
return rgbcolor.test(str);
}
```
3. Add the following to the validator object towards the end of the file:
```
isISRC: isISRC,
isRFC5646: isRFC5646,
isSemVer: isSemVer,
isRGBColor: isRGBColor,
```
4. Look for the phones array just above the isMobilePhone() method.
1. Replace the en-HK regex with:
```
// According to http://www.ofca.gov.hk/filemanager/ofca/en/content_311/no_plan.pdf
'en-HK': /^(\+?852-?)?((4(04[01]|06\d|09[3-9]|20\d|2[2-9]\d|3[3-9]\d|[467]\d{2}|5[1-9]\d|81\d|82[1-9]|8[69]\d|92[3-9]|95[2-9]|98\d)|5([1-79]\d{2})|6(0[1-9]\d|[1-9]\d{2})|7(0[1-9]\d|10[4-79]|11[458]|1[24578]\d|13[24-9]|16[0-8]|19[24579]|21[02-79]|2[456]\d|27[13-6]|3[456]\d|37[4578]|39[0146])|8(1[58]\d|2[45]\d|267|27[5-9]|2[89]\d|3[15-9]\d|32[5-8]|[46-9]\d{2}|5[013-9]\d)|9(0[1-9]\d|1[02-9]\d|[2-8]\d{2}))-?\d{4}|7130-?[0124-8]\d{3}|8167-?2\d{3})$/,
```
2. Add:
```
'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,
'lt-LT': /^(\+370|8)\d{8}$/,
```
5. Replace the isMobilePhone() method with:
```
function isMobilePhone(str, locale) {
assertString(str);
if (locale in phones) {
return phones[locale].test(str);
} else if (locale === 'any') {
return !!Object.values(phones).find(phone => phone.test(str));
}
return false;
}
```
6. Delete the notBase64 regex and replace the isBase64 with:
```
function isBase64(str) {
assertString(str);
// Value length must be divisible by 4.
var len = str.length;
if (!len || len % 4 !== 0) {
return false;
}
try {
if (atob(str)) {
return true;
}
} catch (e) {
return false;
}
}
```
7. Do not replace the test files as they have been converted to xpcshell tests. If there are new methods then add their tests to the `test_sanitizers.js` or `test_validators.js` files as appropriate.
8. To test the library please run the following:
```
./mach xpcshell-test devtools/client/shared/vendor/stringvalidator/
```

15
devtools/client/shared/vendor/stringvalidator/moz.build поставляемый Normal file
Просмотреть файл

@ -0,0 +1,15 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
DIRS += [
'util'
]
XPCSHELL_TESTS_MANIFESTS += ['tests/unit/xpcshell.ini']
DevToolsModules(
'validator.js',
)

Просмотреть файл

@ -0,0 +1,20 @@
"use strict";
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
var Cr = Components.results;
const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
const { console } = Cu.import("resource://gre/modules/Console.jsm", {});
this.validator = require("devtools/client/shared/vendor/stringvalidator/validator");
function describe(suite, testFunc) {
do_print(`\n Test suite: ${suite}`.toUpperCase());
testFunc();
}
function it(description, testFunc) {
do_print(`\n - ${description}:\n`.toUpperCase());
testFunc();
}

Просмотреть файл

@ -0,0 +1,420 @@
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2; fill-column: 80 -*- */
/*
* Copyright 2013 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE.md or:
* http://opensource.org/licenses/BSD-2-Clause
*/
"use strict";
function test(options) {
var args = options.args || [];
args.unshift(null);
Object.keys(options.expect).forEach(function (input) {
args[0] = input;
var result = validator[options.sanitizer](...args);
var expected = options.expect[input];
let argsString = args.join(', ');
if (isNaN(result) && !result.length && isNaN(expected)) {
ok(true, `validator.${options.sanitizer}(${argsString}) returned "${result}"`);
} else {
equal(result, expected, `validator.${options.sanitizer}("${argsString}") ` +
`returned "${result}"`);
}
});
}
function run_test() {
describe('Sanitizers', function () {
it('should sanitize boolean strings', function () {
test({
sanitizer: 'toBoolean',
expect: {
'0': false,
'': false,
'1': true,
'true': true,
'foobar': true,
' ': true,
},
});
test({
sanitizer: 'toBoolean',
args: [true], // strict
expect: {
'0': false,
'': false,
'1': true,
'true': true,
'foobar': false,
' ': false,
},
});
});
it('should trim whitespace', function () {
test({
sanitizer: 'trim',
expect: {
' \r\n\tfoo \r\n\t ': 'foo',
' \r': '',
},
});
test({
sanitizer: 'ltrim',
expect: {
' \r\n\tfoo \r\n\t ': 'foo \r\n\t ',
' \t \n': '',
},
});
test({
sanitizer: 'rtrim',
expect: {
' \r\n\tfoo \r\n\t ': ' \r\n\tfoo',
' \r\n \t': '',
},
});
});
it('should trim custom characters', function () {
test({
sanitizer: 'trim',
args: ['01'],
expect: { '010100201000': '2' },
});
test({
sanitizer: 'ltrim',
args: ['01'],
expect: { '010100201000': '201000' },
});
test({
sanitizer: 'rtrim',
args: ['01'],
expect: { '010100201000': '0101002' },
});
});
it('should convert strings to integers', function () {
test({
sanitizer: 'toInt',
expect: {
'3': 3,
' 3 ': 3,
'2.4': 2,
'foo': NaN,
},
});
test({
sanitizer: 'toInt',
args: [16],
expect: { 'ff': 255 },
});
});
it('should convert strings to floats', function () {
test({
sanitizer: 'toFloat',
expect: {
'2': 2.0,
'2.': 2.0,
'-2.5': -2.5,
'.5': 0.5,
'foo': NaN,
},
});
});
it('should escape HTML', function () {
test({
sanitizer: 'escape',
expect: {
'<script> alert("xss&fun"); </script>':
'&lt;script&gt; alert(&quot;xss&amp;fun&quot;); &lt;&#x2F;script&gt;',
"<script> alert('xss&fun'); </script>":
'&lt;script&gt; alert(&#x27;xss&amp;fun&#x27;); &lt;&#x2F;script&gt;',
'Backtick: `':
'Backtick: &#96;',
'Backslash: \\':
'Backslash: &#x5C;',
},
});
});
it('should unescape HTML', function () {
test({
sanitizer: 'unescape',
expect: {
'&lt;script&gt; alert(&quot;xss&amp;fun&quot;); &lt;&#x2F;script&gt;':
'<script> alert("xss&fun"); </script>',
'&lt;script&gt; alert(&#x27;xss&amp;fun&#x27;); &lt;&#x2F;script&gt;':
"<script> alert('xss&fun'); </script>",
'Backtick: &#96;':
'Backtick: `',
},
});
});
it('should remove control characters (<32 and 127)', function () {
// Check basic functionality
test({
sanitizer: 'stripLow',
expect: {
'foo\x00': 'foo',
'\x7Ffoo\x02': 'foo',
'\x01\x09': '',
'foo\x0A\x0D': 'foo',
},
});
// Unicode safety
test({
sanitizer: 'stripLow',
expect: {
'perch\u00e9': 'perch\u00e9',
'\u20ac': '\u20ac',
'\u2206\x0A': '\u2206',
'\ud83d\ude04': '\ud83d\ude04',
},
});
// Preserve newlines
test({
sanitizer: 'stripLow',
args: [true], // keep_new_lines
expect: {
'foo\x0A\x0D': 'foo\x0A\x0D',
'\x03foo\x0A\x0D': 'foo\x0A\x0D',
},
});
});
it('should sanitize a string based on a whitelist', function () {
test({
sanitizer: 'whitelist',
args: ['abc'],
expect: {
'abcdef': 'abc',
'aaaaaaaaaabbbbbbbbbb': 'aaaaaaaaaabbbbbbbbbb',
'a1b2c3': 'abc',
' ': '',
},
});
});
it('should sanitize a string based on a blacklist', function () {
test({
sanitizer: 'blacklist',
args: ['abc'],
expect: {
'abcdef': 'def',
'aaaaaaaaaabbbbbbbbbb': '',
'a1b2c3': '123',
' ': ' ',
},
});
});
it('should normalize an email based on domain', function () {
test({
sanitizer: 'normalizeEmail',
expect: {
'test@me.com': 'test@me.com',
'some.name@gmail.com': 'somename@gmail.com',
'some.name@googleMail.com': 'somename@gmail.com',
'some.name+extension@gmail.com': 'somename@gmail.com',
'some.Name+extension@GoogleMail.com': 'somename@gmail.com',
'some.name.middleName+extension@gmail.com': 'somenamemiddlename@gmail.com',
'some.name.middleName+extension@GoogleMail.com': 'somenamemiddlename@gmail.com',
'some.name.midd.leNa.me.+extension@gmail.com': 'somenamemiddlename@gmail.com',
'some.name.midd.leNa.me.+extension@GoogleMail.com': 'somenamemiddlename@gmail.com',
'some.name+extension@unknown.com': 'some.name+extension@unknown.com',
'hans@m端ller.com': 'hans@m端ller.com',
'an invalid email address': false,
'': false,
'+extension@gmail.com': false,
'...@gmail.com': false,
'.+extension@googlemail.com': false,
'+a@icloud.com': false,
'+a@outlook.com': false,
'-a@yahoo.com': false,
'some.name.midd..leNa...me...+extension@GoogleMail.com': 'somenamemiddlename@gmail.com',
'"foo@bar"@baz.com': '"foo@bar"@baz.com',
},
});
// Testing all_lowercase switch, should apply to domains not known to be case-insensitive
test({
sanitizer: 'normalizeEmail',
args: [{ all_lowercase: false }],
expect: {
'test@foo.com': 'test@foo.com',
'hans@m端ller.com': 'hans@m端ller.com',
'test@FOO.COM': 'test@foo.com', // Hostname is always lowercased
'blAH@x.com': 'blAH@x.com',
// In case of domains that are known to be case-insensitive, there's a separate switch
'TEST@me.com': 'test@me.com',
'TEST@ME.COM': 'test@me.com',
'SOME.name@GMAIL.com': 'somename@gmail.com',
'SOME.name.middleName+extension@GoogleMail.com': 'somenamemiddlename@gmail.com',
'SOME.name.midd.leNa.me.+extension@gmail.com': 'somenamemiddlename@gmail.com',
'SOME.name@gmail.com': 'somename@gmail.com',
'SOME.name@yahoo.ca': 'some.name@yahoo.ca',
'SOME.name@outlook.ie': 'some.name@outlook.ie',
'SOME.name@me.com': 'some.name@me.com',
},
});
// Testing *_lowercase
test({
sanitizer: 'normalizeEmail',
args: [{
all_lowercase: false,
gmail_lowercase: false,
icloud_lowercase: false,
outlookdotcom_lowercase: false,
yahoo_lowercase: false,
}],
expect: {
'TEST@FOO.COM': 'TEST@foo.com', // all_lowercase
'ME@gMAil.com': 'ME@gmail.com', // gmail_lowercase
'ME@me.COM': 'ME@me.com', // icloud_lowercase
'ME@icloud.COM': 'ME@icloud.com', // icloud_lowercase
'ME@outlook.COM': 'ME@outlook.com', // outlookdotcom_lowercase
'JOHN@live.CA': 'JOHN@live.ca', // outlookdotcom_lowercase
'ME@ymail.COM': 'ME@ymail.com', // yahoo_lowercase
},
});
// Testing all_lowercase
// Should overwrite all the *_lowercase options
test({
sanitizer: 'normalizeEmail',
args: [{
all_lowercase: true,
gmail_lowercase: false, // Overruled
icloud_lowercase: false, // Overruled
outlookdotcom_lowercase: false, // Overruled
yahoo_lowercase: false, // Overruled
}],
expect: {
'TEST@FOO.COM': 'test@foo.com', // all_lowercase
'ME@gMAil.com': 'me@gmail.com', // gmail_lowercase
'ME@me.COM': 'me@me.com', // icloud_lowercase
'ME@icloud.COM': 'me@icloud.com', // icloud_lowercase
'ME@outlook.COM': 'me@outlook.com', // outlookdotcom_lowercase
'JOHN@live.CA': 'john@live.ca', // outlookdotcom_lowercase
'ME@ymail.COM': 'me@ymail.com', // yahoo_lowercase
},
});
// Testing *_remove_dots
test({
sanitizer: 'normalizeEmail',
args: [{
gmail_remove_dots: false,
}],
expect: {
'SOME.name@GMAIL.com': 'some.name@gmail.com',
'SOME.name+me@GMAIL.com': 'some.name@gmail.com',
'my.self@foo.com': 'my.self@foo.com',
},
});
test({
sanitizer: 'normalizeEmail',
args: [{
gmail_remove_dots: true,
}],
expect: {
'SOME.name@GMAIL.com': 'somename@gmail.com',
'SOME.name+me@GMAIL.com': 'somename@gmail.com',
'my.self@foo.com': 'my.self@foo.com',
},
});
// Testing *_remove_subaddress
test({
sanitizer: 'normalizeEmail',
args: [{
gmail_remove_subaddress: false,
icloud_remove_subaddress: false,
outlookdotcom_remove_subaddress: false,
yahoo_remove_subaddress: false, // Note Yahoo uses "-"
}],
expect: {
'foo+bar@unknown.com': 'foo+bar@unknown.com',
'foo+bar@gmail.com': 'foo+bar@gmail.com', // gmail_remove_subaddress
'foo+bar@me.com': 'foo+bar@me.com', // icloud_remove_subaddress
'foo+bar@icloud.com': 'foo+bar@icloud.com', // icloud_remove_subaddress
'foo+bar@live.fr': 'foo+bar@live.fr', // outlookdotcom_remove_subaddress
'foo+bar@hotmail.co.uk': 'foo+bar@hotmail.co.uk', // outlookdotcom_remove_subaddress
'foo-bar@yahoo.com': 'foo-bar@yahoo.com', // yahoo_remove_subaddress
'foo+bar@yahoo.com': 'foo+bar@yahoo.com', // yahoo_remove_subaddress
},
});
test({
sanitizer: 'normalizeEmail',
args: [{
gmail_remove_subaddress: true,
icloud_remove_subaddress: true,
outlookdotcom_remove_subaddress: true,
yahoo_remove_subaddress: true, // Note Yahoo uses "-"
}],
expect: {
'foo+bar@unknown.com': 'foo+bar@unknown.com',
'foo+bar@gmail.com': 'foo@gmail.com', // gmail_remove_subaddress
'foo+bar@me.com': 'foo@me.com', // icloud_remove_subaddress
'foo+bar@icloud.com': 'foo@icloud.com', // icloud_remove_subaddress
'foo+bar@live.fr': 'foo@live.fr', // outlookdotcom_remove_subaddress
'foo+bar@hotmail.co.uk': 'foo@hotmail.co.uk', // outlookdotcom_remove_subaddress
'foo-bar@yahoo.com': 'foo@yahoo.com', // yahoo_remove_subaddress
'foo+bar@yahoo.com': 'foo+bar@yahoo.com', // yahoo_remove_subaddress
},
});
// Testing gmail_convert_googlemaildotcom
test({
sanitizer: 'normalizeEmail',
args: [{
gmail_convert_googlemaildotcom: false,
}],
expect: {
'SOME.name@GMAIL.com': 'somename@gmail.com',
'SOME.name+me@GMAIL.com': 'somename@gmail.com',
'SOME.name+me@googlemail.com': 'somename@googlemail.com',
'SOME.name+me@googlemail.COM': 'somename@googlemail.com',
'SOME.name+me@googlEmail.com': 'somename@googlemail.com',
'my.self@foo.com': 'my.self@foo.com',
},
});
test({
sanitizer: 'normalizeEmail',
args: [{
gmail_convert_googlemaildotcom: true,
}],
expect: {
'SOME.name@GMAIL.com': 'somename@gmail.com',
'SOME.name+me@GMAIL.com': 'somename@gmail.com',
'SOME.name+me@googlemail.com': 'somename@gmail.com',
'SOME.name+me@googlemail.COM': 'somename@gmail.com',
'SOME.name+me@googlEmail.com': 'somename@gmail.com',
'my.self@foo.com': 'my.self@foo.com',
},
});
});
});
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,8 @@
[DEFAULT]
tags = devtools
head = head_stringvalidator.js
firefox-appdir = browser
skip-if = toolkit == 'android'
[test_sanitizers.js]
[test_validators.js]

215
devtools/client/shared/vendor/stringvalidator/util/assert.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,215 @@
// // based on node assert, original notice:
// // NB: The URL to the CommonJS spec is kept just for tradition.
// // node-assert has evolved a lot since then, both in API and behavior.
//
// // http://wiki.commonjs.org/wiki/Unit_Testing/1.0
// //
// // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
// //
// // Originally from narwhal.js (http://narwhaljs.org)
// // Copyright (c) 2009 Thomas Robinson <280north.com>
// //
// // Permission is hereby granted, free of charge, to any person obtaining a copy
// // of this software and associated documentation files (the 'Software'), to
// // deal in the Software without restriction, including without limitation the
// // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// // sell copies of the Software, and to permit persons to whom the Software is
// // furnished to do so, subject to the following conditions:
// //
// // The above copyright notice and this permission notice shall be included in
// // all copies or substantial portions of the Software.
// //
// // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"use strict";
var regex = /\s*function\s+([^\(\s]*)\s*/;
var functionsHaveNames = (function () {
return function foo() {}.name === "foo";
}());
function assert(value, message) {
if (!value) {
fail(value, true, message, "==", assert.ok);
}
}
assert.equal = function equal(actual, expected, message) {
if (actual != expected) {
fail(actual, expected, message, "==", assert.equal);
}
};
assert.throws = function (block, error, message) {
_throws(true, block, error, message);
};
function _throws(shouldThrow, block, expected, message) {
var actual;
if (typeof block !== "function") {
throw new TypeError(`"block" argument must be a function`);
}
if (typeof expected === "string") {
message = expected;
expected = null;
}
actual = _tryBlock(block);
message = (expected && expected.name ? " (" + expected.name + ")." : ".") +
(message ? " " + message : ".");
if (shouldThrow && !actual) {
fail(actual, expected, "Missing expected exception" + message);
}
var userProvidedMessage = typeof message === "string";
var isUnwantedException = !shouldThrow && isError(actual);
var isUnexpectedException = !shouldThrow && actual && !expected;
if ((isUnwantedException &&
userProvidedMessage &&
expectedException(actual, expected)) ||
isUnexpectedException) {
fail(actual, expected, "Got unwanted exception" + message);
}
if ((shouldThrow && actual && expected &&
!expectedException(actual, expected)) || (!shouldThrow && actual)) {
throw actual;
}
}
function fail(actual, expected, message, operator, stackStartFunction) {
throw new assert.AssertionError({
message: message,
actual: actual,
expected: expected,
operator: operator,
stackStartFunction: stackStartFunction
});
}
assert.fail = fail;
assert.AssertionError = function AssertionError(options) {
this.name = "AssertionError";
this.actual = options.actual;
this.expected = options.expected;
this.operator = options.operator;
if (options.message) {
this.message = options.message;
this.generatedMessage = false;
} else {
this.message = getMessage(this);
this.generatedMessage = true;
}
var stackStartFunction = options.stackStartFunction || fail;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, stackStartFunction);
} else {
// non v8 browsers so we can have a stacktrace
var err = new Error();
if (err.stack) {
var out = err.stack;
// try to strip useless frames
var fn_name = getName(stackStartFunction);
var idx = out.indexOf("\n" + fn_name);
if (idx >= 0) {
// once we have located the function frame
// we need to strip out everything before it (and its line)
var next_line = out.indexOf("\n", idx + 1);
out = out.substring(next_line + 1);
}
this.stack = out;
}
}
};
function expectedException(actual, expected) {
if (!actual || !expected) {
return false;
}
if (Object.prototype.toString.call(expected) == "[object RegExp]") {
return expected.test(actual);
}
try {
if (actual instanceof expected) {
return true;
}
} catch (e) {
// Ignore. The instanceof check doesn"t work for arrow functions.
}
if (Error.isPrototypeOf(expected)) {
return false;
}
return expected.call({}, actual) === true;
}
function _tryBlock(block) {
var error;
try {
block();
} catch (e) {
error = e;
}
return error;
}
function isError(obj) {
return obj instanceof Error;
}
function isFunction(value) {
return typeof value === "function";
}
function getMessage(self) {
return truncate(inspect(self.actual), 128) + " " +
self.operator + " " +
truncate(inspect(self.expected), 128);
}
function getName(func) {
if (!isFunction(func)) {
return null;
}
if (functionsHaveNames) {
return func.name;
}
var str = func.toString();
var match = str.match(regex);
return match && match[1];
}
function truncate(s, n) {
if (typeof s === "string") {
return s.length < n ? s : s.slice(0, n);
}
return s;
}
function inspect(something) {
if (functionsHaveNames || !isFunction(something)) {
throw new Error(something);
}
var rawname = getName(something);
var name = rawname ? ": " + rawname : "";
return "[Function" + name + "]";
}
exports.assert = assert;

9
devtools/client/shared/vendor/stringvalidator/util/moz.build поставляемый Normal file
Просмотреть файл

@ -0,0 +1,9 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
DevToolsModules(
'assert.js',
)

1489
devtools/client/shared/vendor/stringvalidator/validator.js поставляемый Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -158,6 +158,7 @@
<li><a href="about:license#ucal">University of California License</a></li>
<li><a href="about:license#hunspell-en-US">US English Spellchecking Dictionary Licenses</a></li>
<li><a href="about:license#v8">V8 License</a></li>
<li><a href="about:license#validator">Validator License</a></li>
<li><a href="about:license#vtune">VTune License</a></li>
<li><a href="about:license#webrtc">WebRTC License</a></li>
<li><a href="about:license#x264">x264 License</a></li>
@ -6092,6 +6093,37 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</pre>
<hr>
<h1><a id="validator"></a>Validator License</h1>
<p>This license applies to certain files in the directory
<code>devtools/shared/stringvalidator/</code>,
</p>
<pre>
Copyright (c) 2016 Chris O"Hara <cohara87@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
</pre>
<hr>