Permalink
Browse files

fix validates.

  • Loading branch information...
1 parent 542e487 commit e65ba696cdd1db49dcf424878df7c3d8511a95ef @mattn committed Mar 9, 2012
Showing with 21 additions and 23 deletions.
  1. +8 −0 autoload/json.vim
  2. +13 −23 autoload/jsonrpc.vim
View
@@ -69,6 +69,14 @@ endfunction
function! json#decode(json)
let json = iconv(a:json, "utf-8", &encoding)
+ if substitute(substitute(substitute(
+ \ json,
+ \ '\\\%(["\\/bfnrt]\|u[0-9a-fA-F]\{4}\)', '\@', 'g'),
+ \ '"[^\"\\\n\r]*\"\|true\|false\|null\|-\?\d\+'
+ \ . '\%(\.\d*\)\?\%([eE][+\-]\{-}\d\+\)\?', ']', 'g'),
+ \ '\%(^\|:\|,\)\%(\s*\[\)\+', '', 'g') !~ '^[\],:{} \t\n]*$'
+ throw json
+ endif
let json = substitute(json, '\n', '', 'g')
let json = substitute(json, '\\u34;', '\\"', 'g')
let json = substitute(json, '\\u\(\x\x\x\x\)', '\=s:nr2enc_char("0x".submatch(1))', 'g')
View
@@ -15,31 +15,21 @@ function! jsonrpc#call(uri, func, args)
\ 'params': a:args,
\})
let res = http#post(a:uri, data, {"Content-Type": "application/json"})
- if res.content != '' &&
- \ substitute(substitute(substitute(
- \ res.content,
- \ '\\\%(["\\/bfnrt]\|u[0-9a-fA-F]\{4}\)', '\@', 'g'),
- \ '"[^\"\\\n\r]*\"\|true\|false\|null\|-\?\d\+'
- \ . '\%(\.\d*\)\?\%([eE][+\-]\{-}\d\+\)\?', ']', 'g'),
- \ '\%(^\|:\|,\)\%(\s*\[\)\+', '', 'g') =~ '^[\],:{} \t\n]*$'
- let obj = json#decode(res.content)
- if has_key(obj, 'error')
- let err = obj.error
- if type(err) == 0 && err != 0
- throw err
- elseif type(err) == 1 && err != ''
- throw err
- elseif type(err) == 2 && err != "function('json#null')"
- throw err
- endif
- endif
- if has_key(obj, 'result')
- return obj.result
+ let obj = json#decode(res.content)
+ if has_key(obj, 'error')
+ let err = obj.error
+ if type(err) == 0 && err != 0
+ throw err
+ elseif type(err) == 1 && err != ''
+ throw err
+ elseif type(err) == 2 && err != "function('json#null')"
+ throw err
endif
- throw "Parse Error"
- else
- throw res.content
endif
+ if has_key(obj, 'result')
+ return obj.result
+ endif
+ throw "Parse Error"
endfunction
function! jsonrpc#wrap(contexts)

0 comments on commit e65ba69

Please sign in to comment.