Bug 853019 - Web Activities' regexp should have a behaviour closer to HTML's pattern. r=mounir

This commit is contained in:
Andrea Marchesini 2013-03-27 11:32:34 -04:00
Родитель e8837eed1a
Коммит 890787eb92
2 изменённых файлов: 18 добавлений и 18 удалений

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

@ -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'}}));
}