Skip to content

Commit

Permalink
fixed rest route start with / problem
Browse files Browse the repository at this point in the history
  • Loading branch information
ldarren committed Aug 16, 2016
1 parent 63d0697 commit 564a1d7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "pico-common",
"version": "0.5.12",
"version": "0.5.13",
"description": "pico common tools",
"main": "pico.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion pico.js
Expand Up @@ -511,7 +511,8 @@ define('pico/str', function(){
},
matchRestCode=function(units,codes,params){
if (units.length < codes.length) return false
for(var i=0,u,c; c=codes[i]; i++){
for(var i=0,u,c,l=codes.length; i<l; i++){
c=codes[i]
u=units.shift()
if (Array.isArray(c)){
if (0!==u.indexOf(c[0])) return false
Expand Down
2 changes: 1 addition & 1 deletion pico.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pico.min.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion plugins/str.js
Expand Up @@ -44,7 +44,8 @@ define('pico/str', function(){
},
matchRestCode=function(units,codes,params){
if (units.length < codes.length) return false
for(var i=0,u,c; c=codes[i]; i++){
for(var i=0,u,c,l=codes.length; i<l; i++){
c=codes[i]
u=units.shift()
if (Array.isArray(c)){
if (0!==u.indexOf(c[0])) return false
Expand Down
12 changes: 10 additions & 2 deletions tests.js
Expand Up @@ -225,15 +225,15 @@ ensure('ensure restful params parser: url/v%version/pushPackage/:pushId',functio
api=str.execRest('url/v1/pushPackage/web.com.domain.app',build,params)
cb(null, api===route && 1===params.version && 'web.com.domain.app'===params.pushId)
})
ensure('ensure restful wildcard parser, route:url/v%version/path/#path',function(cb){
ensure('ensure restful wildcard parser: url/v%version/path/#path',function(cb){
var
route='url/v%version/path/#path',
build=str.compileRest(route),
params={},
api=str.execRest('url/v1/path/web/com/domain/app',build,params)
cb(null, api===route && 1===params.version && 'web/com/domain/app'===params.path)
})
ensure('ensure restful optional parser, route:url/v%version|device/:deviceToken|path/#path',function(cb){
ensure('ensure restful optional parser: url/v%version|device/:deviceToken|path/#path',function(cb){
var
route='url/v%version|device/:deviceToken|path/#path',
build=str.compileRest(route),
Expand All @@ -248,3 +248,11 @@ ensure('ensure restful optional parser, route:url/v%version|device/:deviceToken|
if(api!==route || 1!==params.version) return cb(null, false)
cb(null, true)
})
ensure('ensure restful optional parser2: /:appName|#appPath',function(cb){
var
route='/:appName|#appPath',
build=str.compileRest(route),
params={},
api=str.execRest('/msair',build,params)
cb(null, api===route && 'msair'===params.appName)
})

0 comments on commit 564a1d7

Please sign in to comment.