Commit 67889ac9 authored by Rob Jonson's avatar Rob Jonson Committed by Rémi Denis-Courmont

Move character escaping from the model contents, to the output helpers.

This is more reliable for ensuring everythign is escaped.
This allows different escaping for xml and json
Signed-off-by: default avatarRémi Denis-Courmont <remi@remlab.net>
parent 7984b19c
...@@ -40,17 +40,17 @@ print('<root>\n') ...@@ -40,17 +40,17 @@ print('<root>\n')
for i,e in ipairs(browseTable.element._array) do for i,e in ipairs(browseTable.element._array) do
print('<element ') print('\n<element ')
for k,v in pairs(e) do for k,v in pairs(e) do
print(" "..k.."='"..v.."'") print(" "..httprequests.xmlString(k).."='"..httprequests.xmlString(v).."'")
end end
print('/>') print('/>')
end end
print('</root>') print('\n</root>')
?> ?>
...@@ -37,7 +37,7 @@ local printleaf = function(item) ...@@ -37,7 +37,7 @@ local printleaf = function(item)
for k,v in pairs(item) do for k,v in pairs(item) do
if (k~="type") then if (k~="type") then
print(" "..k.."=\""..v.."\"") print(" "..httprequests.xmlString(k).."=\""..httprequests.xmlString(v).."\"")
end end
end end
...@@ -56,7 +56,7 @@ local printnode = function(item) ...@@ -56,7 +56,7 @@ local printnode = function(item)
elseif (k=="children") then elseif (k=="children") then
children=v._array children=v._array
else else
print(" "..k.."=\""..v.."\"") print(" "..httprequests.xmlString(k).."=\""..httprequests.xmlString(v).."\"")
end end
end end
......
...@@ -49,7 +49,7 @@ local item = vlc.input.item() ...@@ -49,7 +49,7 @@ local item = vlc.input.item()
if item then if item then
local metas = item:metas() local metas = item:metas()
for k,v in pairs(metas) do for k,v in pairs(metas) do
print("<info name='"..vlc.strings.convert_xml_special_chars(k).."'>"..vlc.strings.convert_xml_special_chars(v).."</info>") print("<info name='"..httprequests.xmlString(k).."'>"..httprequests.xmlString(v).."</info>")
end end
end end
?> ?>
...@@ -58,9 +58,9 @@ local item = vlc.input.item() ...@@ -58,9 +58,9 @@ local item = vlc.input.item()
if item then if item then
local info = item:info() local info = item:info()
for k, v in pairs(info) do for k, v in pairs(info) do
print("<category name='"..vlc.strings.convert_xml_special_chars(k).."'>") print("<category name='"..httprequests.xmlString(k).."'>")
for k2, v2 in pairs(v) do for k2, v2 in pairs(v) do
print("<info name='"..vlc.strings.convert_xml_special_chars(k2).."'>"..vlc.strings.convert_xml_special_chars(v2).."</info>") print("<info name='"..httprequests.xmlString(k2).."'>"..httprequests.xmlString(v2).."</info>")
end end
print("</category>") print("</category>")
end end
...@@ -73,7 +73,7 @@ local item = vlc.input.item() ...@@ -73,7 +73,7 @@ local item = vlc.input.item()
local stats = item:stats() local stats = item:stats()
for k,v in pairs(stats) do for k,v in pairs(stats) do
local tag = string.gsub(k,"_","") local tag = string.gsub(k,"_","")
print("<"..tag..">"..tostring(v).."</"..tag..">\n") print("<"..httprequests.xmlString(tag)..">"..httprequests.xmlString(v).."</"..httprequests.xmlString(tag)..">\n")
end end
end end
?> ?>
......
...@@ -187,7 +187,7 @@ end ...@@ -187,7 +187,7 @@ end
--utilities for formatting output --utilities for formatting output
local function xmlString(s) function xmlString(s)
if (type(s)=="string") then if (type(s)=="string") then
return vlc.strings.convert_xml_special_chars(s) return vlc.strings.convert_xml_special_chars(s)
else else
...@@ -252,7 +252,7 @@ local printXmlKeyValue = function (k,v,indent) ...@@ -252,7 +252,7 @@ local printXmlKeyValue = function (k,v,indent)
end end
if (k) then if (k) then
print("</"..k..">") print("</"..xmlString(k)..">")
end end
end end
...@@ -301,7 +301,7 @@ parseplaylist = function (item) ...@@ -301,7 +301,7 @@ parseplaylist = function (item)
if (item.children) then if (item.children) then
local result={} local result={}
local name = vlc.strings.convert_xml_special_chars(item.name or "") local name = (item.name or "")
result["type"]="node" result["type"]="node"
result.id=tostring(item.id) result.id=tostring(item.id)
...@@ -321,7 +321,8 @@ parseplaylist = function (item) ...@@ -321,7 +321,8 @@ parseplaylist = function (item)
return result return result
else else
local result={} local result={}
local name, path = vlc.strings.convert_xml_special_chars(item.name or "", item.path or "") local name, path = item.name or ""
local path = item.path or ""
local current_item = vlc.input.item() local current_item = vlc.input.item()
-- Is the item the one currently played -- Is the item the one currently played
...@@ -376,7 +377,7 @@ getbrowsetable = function () ...@@ -376,7 +377,7 @@ getbrowsetable = function ()
if f == ".." or not string.match(f,"^%.") then if f == ".." or not string.match(f,"^%.") then
local df = common.realpath(dir..f) local df = common.realpath(dir..f)
local s = vlc.net.stat(df) local s = vlc.net.stat(df)
local path, name = vlc.strings.convert_xml_special_chars( df, f ) local path, name = df, f
local element={} local element={}
for k,v in pairs(s) do for k,v in pairs(s) do
...@@ -485,10 +486,10 @@ local aout = vlc.object.aout() ...@@ -485,10 +486,10 @@ local aout = vlc.object.aout()
local streamTable={} local streamTable={}
for k2, v2 in pairs(v) do for k2, v2 in pairs(v) do
local tag = string.gsub(k2," ","_") local tag = string.gsub(k2," ","_")
streamTable[xmlString(tag)]=xmlString(v2) streamTable[tag]=v2
end end
s.information.category[xmlString(k)]=streamTable s.information.category[k]=streamTable
end end
s.stats={} s.stats={}
...@@ -496,7 +497,7 @@ local aout = vlc.object.aout() ...@@ -496,7 +497,7 @@ local aout = vlc.object.aout()
local statsdata = item:stats() local statsdata = item:stats()
for k,v in pairs(statsdata) do for k,v in pairs(statsdata) do
local tag = string.gsub(k,"_","") local tag = string.gsub(k,"_","")
s.stats[tag]=xmlString(v) s.stats[tag]=v
end end
end end
return s return s
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment