Add another test to validation suite

RESOLVED FIXED in 5.3

Status

addons.mozilla.org Graveyard
Developer Pages
RESOLVED FIXED
9 years ago
3 years ago

People

(Reporter: clouserw, Assigned: rjwalsh)

Tracking

unspecified

Details

Attachments

(1 attachment)

(Reporter)

Description

9 years ago
From email:

Simply testing for Function including static strings passed as function
body would lead to false positives and has very limited merit.
See the setTimeout discussion
https://bugzilla.mozilla.org/show_bug.cgi?id=509500

It is Function ([arg1[, arg2[, ... argN]],] functionBody)
The new keyword is not required.

I got two suggestions for a regular expression.
Tested both against the following vectors:
var allowed = [
	'Function("abc")',
	"Function('abc')",
	'Function(d, "abc")',
	"Function(d, \n'abc')",
	"Function( d, 'abc' )",
	"Function(d,'abc')",
	'Function(ab, cd, "a"+"bc"+"d")',
];
var bad = [
	"Function(abc)",
	"Function('ab' + abc)",
	'Function(a + "bc" + d)',
	'Function(ab, \ncd)',
	'Function(ab,cd)',
	'Function( ab, cd )',
	'Function(ab, cd, a + "bc" + d)',
	'Function(ab, cd, a + "bc" + "d")',
	'Function(ab, cd, "a"+"bc"+d)',
	'Function(ab, cd, "a"+b+"bc"+d)',
	'Function(ab, cd, a+"a"+"bc"+d)',
	'Function( ab, cd, a + "a" + "bc" + d )',
];

Simple one:
/\bFunction\(.*?[\w\d_]\s*?\)/sm
Or javascripty (i.e. no dotall/s):
/\bFunction\([\S\s]*?[\w\d_]\s*?\)/m

Will work for all except:
Function(ab, cd, a + "bc" + "d")


Better, but more complex:
/\bFunction\((?:.*?[\w\d_]|.*?,.*?(?:['"]\s*?[+]\s*?[\w_]|[\w\d_]\s*?[+]\s*?['"]).*?)\s*?\)/sm
or javascripty
/\bFunction\((?:[\S\s]*?[\w\d_]|[\S\s]*?,[\S\s]*?(?:['"]\s*?[+]\s*?[\w_]|[\w\d_]\s*?[+]\s*?['"])[\S\s]*?)\s*?\)/m

Works for all tests

Cheers
Nils
Assignee: nobody → rjbuild1088
(Reporter)

Updated

9 years ago
Target Milestone: 5.2 → 5.3
(Assignee)

Comment 1

9 years ago
Created attachment 409490 [details] [diff] [review]
Fix using Nils' regex

Using the second-to-last regex in comment #0.
Attachment #409490 - Flags: review?(clouserw)
(Reporter)

Updated

9 years ago
Attachment #409490 - Flags: review?(clouserw) → review+
(Assignee)

Comment 2

9 years ago
Fixed in r54982.
Status: NEW → RESOLVED
Last Resolved: 9 years ago
Resolution: --- → FIXED
(Reporter)

Updated

9 years ago
Duplicate of this bug: 522722
Product: addons.mozilla.org → addons.mozilla.org Graveyard
You need to log in before you can comment on or make changes to this bug.