Closed Bug 518439 Opened 15 years ago Closed 15 years ago

Add another test to validation suite

Categories

(addons.mozilla.org Graveyard :: Developer Pages, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: clouserw, Assigned: rjwalsh)

References

Details

Attachments

(1 file)

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
Target Milestone: 5.2 → 5.3
Using the second-to-last regex in comment #0.
Attachment #409490 - Flags: review?(clouserw)
Attachment #409490 - Flags: review?(clouserw) → review+
Fixed in r54982.
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Product: addons.mozilla.org → addons.mozilla.org Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: