Skip to content

Commit

Permalink
Handle special cases when root path includes trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
dpino committed Jul 6, 2017
1 parent be73854 commit 0a47c05
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/lib/yang/data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,9 @@ local function value_serializer(typ)
end

function xpath_printer_from_grammar(production, print_default, root)
if #root > 1 and root:sub(#root, #root) == '/' then
root = root:sub(1, #root-1)
end
local handlers = {}
local translators = {}
local function printer(keyword, production, printers)
Expand All @@ -711,7 +714,8 @@ function xpath_printer_from_grammar(production, print_default, root)
file:write(encode_yang_string(str))
end
local function print_keyword(k, file, path)
file:write(root..'/'..path)
path = path:sub(1, 1) ~= '[' and root..'/'..path or root..path
file:write(path)
print_string(k, file)
file:write(' ')
end
Expand Down Expand Up @@ -812,29 +816,33 @@ function xpath_printer_from_grammar(production, print_default, root)
return function(data, file, path)
for entry in data:iterate() do
local key = compose_key(entry.key)
print_value(entry.value, file, keyword..key..'/')
local path = keyword and keyword..key..'/' or key..'/'
print_value(entry.value, file, path)
end
end
elseif production.string_key then
local id = normalize_id(production.string_key)
return function(data, file, path)
for key, value in pairs(data) do
local key = compose_key({[id]=key})
print_value(value, file, keyword..key..'/')
local path = keyword and keyword..key..'/' or key..'/'
print_value(value, file, path)
end
end
elseif production.key_ctype then
return function(data, file, path)
for key, value in cltable.pairs(data) do
local key = compose_key(key)
print_value(value, file, keyword..key..'/')
local path = keyword and keyword..key..'/' or key..'/'
print_value(value, file, path)
end
end
else
return function(data, file, path)
for key, value in pairs(data) do
print_key(key, file, path..'/')
print_value(value, file, keyword..key..'/')
local key = compose_key(key)
local path = keyword and keyword..key..'/' or key..'/'
print_value(value, file, path)
end
end
end
Expand Down

0 comments on commit 0a47c05

Please sign in to comment.