Skip to content

Commit

Permalink
Fix problem with key escaping in _object
Browse files Browse the repository at this point in the history
  • Loading branch information
dolik-rce committed Mar 10, 2016
1 parent d94c308 commit a6e58b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/json.bash
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ JSON.object() {
JSON._object() {
local key=$1
if [[ -n $key && $key != "/" ]]; then
key=${key/\//\\/}
grep -E "^$key/" |
sed "s/^$key//"
key=${key//\//\\/}
sed -n "s/^$key//p"
else
cat
fi
Expand Down
7 changes: 6 additions & 1 deletion test/keys.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source test/setup

use Test::More tests 5
use Test::More tests 6
use JSON

tree1=$(cat test/keys.json | JSON.load)
Expand All @@ -28,3 +28,8 @@ is "$keys" \
keys="$(JSON.keys '/' tree1)"
is "$keys" "description"$'\n'"files" \
"JSON.keys '/'" #'

keys="$(JSON.keys '/files/file 2.txt' tree1)"
is "$keys" \
"content"$'\n'"type" \
"JSON.keys '/files/file 2.txt'" #'

0 comments on commit a6e58b8

Please sign in to comment.