Skip to content

Commit 47609a0

Browse files
committed
release(1.2.2): Allow custom id validation
1 parent 9d6eb3b commit 47609a0

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

controller.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ var Controller = Class.extend(
7878
*/
7979
restfulRouting: true,
8080

81+
/**
82+
* Regex used to determine what constitutes a valid
83+
*
84+
* @default true
85+
* @type {Boolean}
86+
*/
87+
idRegex: /(^[0-9]+$|^[0-9a-fA-F]{24}$)/,
88+
8189
/**
8290
* Use this function to attach your controller's to routes (either express or restify are supported)
8391
* @return {Function} returns constructor function
@@ -284,7 +292,7 @@ var Controller = Class.extend(
284292
, actionRouting = this.Class.actionRouting
285293
, actionMethod = /\/([a-zA-z\.]+)(\/?|\?.*|\#.*)?$/ig.test( req.url ) ? RegExp.$1 + 'Action' : ( req.params.action !== undefined ? req.params.action : false )
286294
, restfulRouting = this.Class.restfulRouting
287-
, idRegex = /(^[0-9]+$|^[0-9a-fA-F]{24}$)/
295+
, idRegex = this.Class.idRegex
288296
, hasIdParam = req.params && req.params.id !== undefined ? true : false
289297
, id = !!hasIdParam && idRegex.test( req.params.id ) ? req.params.id : false
290298
, hasActionParam = req.params && req.params.action !== undefined ? true : false

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "clever-controller",
33
"description": "Lightning-fast flexible controller prototype",
4-
"version": "1.2.1",
4+
"version": "1.2.2",
55
"main": "controller.js",
66
"repository": {
77
"type": "git",

0 commit comments

Comments
 (0)