lib/airborne/path_matcher.rb in airborne-0.1.8 vs lib/airborne/path_matcher.rb in airborne-0.1.9
- old
+ new
@@ -1,9 +1,11 @@
module Airborne
+ class PathError < StandardError; end
module PathMatcher
def get_by_path(path, json, &block)
+ raise PathError, "Ivalid Path, contains '..'" if /\.\./ =~ path
type = false
parts = path.split('.')
parts.each_with_index do |part, index|
if part == '*' || part == '?'
ensure_array(path, json)
@@ -12,11 +14,15 @@
walk_with_path(type, index, path, parts, json, &block)
return
end
next
end
- json = process_json(part, json)
+ begin
+ json = process_json(part, json)
+ rescue
+ raise PathError, "Expected #{json.class}\nto to be an object with property #{part}"
+ end
end
if type == '*'
expect_all(json, &block)
elsif type == '?'
expect_one(path, json, &block)
@@ -62,10 +68,10 @@
item_count = json.length
error_count = 0
json.each do |part|
begin
yield part
- rescue Exception => e
+ rescue Exception
error_count += 1
ensure_match_one(path, item_count, error_count)
end
end
end