[vlc-commits] Move character escaping from the model contents, to the output helpers.

Rob Jonson git at videolan.org
Tue Sep 27 17:07:29 CEST 2011


vlc | branch: master | Rob Jonson <rob at hobbyistsoftware.com> | Tue Sep 27 10:45:30 2011 +0100| [67889ac99eceb167f4fade5c73a3438ace4925ff] | committer: 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: Rémi Denis-Courmont <remi at remlab.net>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=67889ac99eceb167f4fade5c73a3438ace4925ff
---

 share/lua/http/requests/browse.xml      |    6 +++---
 share/lua/http/requests/playlist.xml    |    4 ++--
 share/lua/http/requests/status.xml      |    8 ++++----
 share/lua/intf/modules/httprequests.lua |   17 +++++++++--------
 4 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/share/lua/http/requests/browse.xml b/share/lua/http/requests/browse.xml
index b65d2b2..0afff8f 100644
--- a/share/lua/http/requests/browse.xml
+++ b/share/lua/http/requests/browse.xml
@@ -40,17 +40,17 @@ print('<root>\n')
 
 
 for i,e in ipairs(browseTable.element._array) do
-	print('<element ')
+	print('\n<element ')
 
 	for k,v in pairs(e) do
-		print(" "..k.."='"..v.."'")
+		print(" "..httprequests.xmlString(k).."='"..httprequests.xmlString(v).."'")
 	end
 
 	print('/>')
 end
 
 
-print('</root>')
+print('\n</root>')
 
 ?>
 
diff --git a/share/lua/http/requests/playlist.xml b/share/lua/http/requests/playlist.xml
index 745237f..8b8930b 100644
--- a/share/lua/http/requests/playlist.xml
+++ b/share/lua/http/requests/playlist.xml
@@ -37,7 +37,7 @@ local printleaf = function(item)
 	for k,v in pairs(item) do
 
 		if (k~="type") then
-			print(" "..k.."=\""..v.."\"")
+			print(" "..httprequests.xmlString(k).."=\""..httprequests.xmlString(v).."\"")
 		end
     end
 
@@ -56,7 +56,7 @@ local printnode = function(item)
 		elseif (k=="children") then
 			children=v._array
 		else
-			print(" "..k.."=\""..v.."\"")
+			print(" "..httprequests.xmlString(k).."=\""..httprequests.xmlString(v).."\"")
 		end
     end
 
diff --git a/share/lua/http/requests/status.xml b/share/lua/http/requests/status.xml
index c84f917..ef400ed 100644
--- a/share/lua/http/requests/status.xml
+++ b/share/lua/http/requests/status.xml
@@ -49,7 +49,7 @@ local item = vlc.input.item()
       if item then
         local metas = item:metas()
         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
     ?>
@@ -58,9 +58,9 @@ local item = vlc.input.item()
     if item then
       local info = item:info()
       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
-            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
         print("</category>")
       end
@@ -73,7 +73,7 @@ local item = vlc.input.item()
       local stats = item:stats()
       for k,v in pairs(stats) do
         local tag = string.gsub(k,"_","")
-        print("<"..tag..">"..tostring(v).."</"..tag..">\n")
+        print("<"..httprequests.xmlString(tag)..">"..httprequests.xmlString(v).."</"..httprequests.xmlString(tag)..">\n")
       end
     end
   ?>
diff --git a/share/lua/intf/modules/httprequests.lua b/share/lua/intf/modules/httprequests.lua
index f68683a..4bcf0df 100644
--- a/share/lua/intf/modules/httprequests.lua
+++ b/share/lua/intf/modules/httprequests.lua
@@ -187,7 +187,7 @@ end
 
 --utilities for formatting output
 
-local function xmlString(s)
+function xmlString(s)
   if (type(s)=="string") then
   	return vlc.strings.convert_xml_special_chars(s)
   else
@@ -252,7 +252,7 @@ local printXmlKeyValue = function (k,v,indent)
     end
 
     if (k) then
-		print("</"..k..">")
+		print("</"..xmlString(k)..">")
 	end
 end
 
@@ -301,7 +301,7 @@ parseplaylist = function (item)
 
 	if (item.children) then
 		local result={}
-		local name = vlc.strings.convert_xml_special_chars(item.name or "")
+		local name = (item.name or "")
 
 		result["type"]="node"
 		result.id=tostring(item.id)
@@ -321,7 +321,8 @@ parseplaylist = function (item)
 		return result
 	else
 		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()
 
 		-- Is the item the one currently played
@@ -376,7 +377,7 @@ getbrowsetable = function ()
 				if f == ".." or not string.match(f,"^%.") then
 				local df = common.realpath(dir..f)
 				local s = vlc.net.stat(df)
-				local path, name = vlc.strings.convert_xml_special_chars( df, f )
+				local path, name =  df, f
 				local element={}
 
 				for k,v in pairs(s) do
@@ -485,10 +486,10 @@ local aout = vlc.object.aout()
 			local streamTable={}
 			for k2, v2 in pairs(v) do
 				local tag = string.gsub(k2," ","_")
-				streamTable[xmlString(tag)]=xmlString(v2)
+				streamTable[tag]=v2
 			end
 
-			s.information.category[xmlString(k)]=streamTable
+			s.information.category[k]=streamTable
 		end
 
 		s.stats={}
@@ -496,7 +497,7 @@ local aout = vlc.object.aout()
 		local statsdata = item:stats()
       	for k,v in pairs(statsdata) do
         	local tag = string.gsub(k,"_","")
-        s.stats[tag]=xmlString(v)
+        s.stats[tag]=v
       end
 	end
 	return s



More information about the vlc-commits mailing list