зеркало из https://github.com/mozilla/gecko-dev.git
Bug 853019 - Web Activities' regexp should have a behaviour closer to HTML's pattern. r=mounir
This commit is contained in:
Родитель
e8837eed1a
Коммит
890787eb92
|
@ -27,18 +27,16 @@ this.ActivitiesServiceFilter = {
|
|||
}
|
||||
}
|
||||
|
||||
// Regexp.
|
||||
if (('regexp' in aFilterObj)) {
|
||||
var regexp = String(aFilterObj.regexp);
|
||||
// Pattern.
|
||||
if (('pattern' in aFilterObj)) {
|
||||
var pattern = String(aFilterObj.pattern);
|
||||
|
||||
if (regexp[0] != "/")
|
||||
return false;
|
||||
var patternFlags = '';
|
||||
if (('patternFlags' in aFilterObj)) {
|
||||
patternFlags = String(aFilterObj.patternFlags);
|
||||
}
|
||||
|
||||
var pos = regexp.lastIndexOf("/");
|
||||
if (pos == 0)
|
||||
return false;
|
||||
|
||||
var re = new RegExp(regexp.substring(1, pos), regexp.substr(pos + 1));
|
||||
var re = new RegExp('^(?:' + pattern + ')$', patternFlags);
|
||||
return re.test(aValue);
|
||||
}
|
||||
|
||||
|
|
|
@ -137,15 +137,17 @@ function run_test() {
|
|||
do_check_false(ActivitiesServiceFilter.match({a: 42},
|
||||
{a: { max: '0' }}));
|
||||
|
||||
// String + RegExp
|
||||
// String + Pattern
|
||||
do_check_true(ActivitiesServiceFilter.match({a: 'foobar'},
|
||||
{a: { required: true, regexp: '/^foobar/'}}));
|
||||
{a: { required: true, pattern: 'foobar'}}));
|
||||
do_check_false(ActivitiesServiceFilter.match({a: 'aafoobar'},
|
||||
{a: { required: true, regexp: '/^foobar/'}}));
|
||||
do_check_true(ActivitiesServiceFilter.match({a: 'aaFOOsdsad'},
|
||||
{a: { required: true, regexp: '/foo/i'}}));
|
||||
do_check_true(ActivitiesServiceFilter.match({a: 'aafoobarasdsad'},
|
||||
{a: { required: true, regexp: '/foo/'}}));
|
||||
{a: { required: true, pattern: 'foobar'}}));
|
||||
do_check_false(ActivitiesServiceFilter.match({a: 'aaFOOsdsad'},
|
||||
{a: { required: true, regexp: '/foo/'}}));
|
||||
{a: { required: true, pattern: 'foo', patternFlags: 'i'}}));
|
||||
do_check_false(ActivitiesServiceFilter.match({a: 'aafoobarasdsad'},
|
||||
{a: { required: true, pattern: 'foo'}}));
|
||||
do_check_false(ActivitiesServiceFilter.match({a: 'aaFOOsdsad'},
|
||||
{a: { required: true, pattern: 'foobar'}}));
|
||||
do_check_true(ActivitiesServiceFilter.match({a: 'FoOBaR'},
|
||||
{a: { required: true, pattern: 'foobar', patternFlags: 'i'}}));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче