[xiph-commits] r19109 - icecast/trunk/icecast/web
dm8tbr at svn.xiph.org
dm8tbr at svn.xiph.org
Sun Mar 9 05:26:15 PDT 2014
Author: dm8tbr
Date: 2014-03-09 05:26:15 -0700 (Sun, 09 Mar 2014)
New Revision: 19109
Modified:
icecast/trunk/icecast/web/xml2json.xslt
Log:
Silence direct calls, add partial array support.
- The XSLT will now return empty if called directly.
This is a security measure to prevent unintended data leakage.
- Adding partial array support to print sources in an array.
Code lifted from:
https://code.google.com/p/xml2json-xslt/issues/detail?id=3
Modified: icecast/trunk/icecast/web/xml2json.xslt
===================================================================
--- icecast/trunk/icecast/web/xml2json.xslt 2014-03-09 12:19:35 UTC (rev 19108)
+++ icecast/trunk/icecast/web/xml2json.xslt 2014-03-09 12:26:15 UTC (rev 19109)
@@ -27,7 +27,10 @@
<xsl:output indent="no" omit-xml-declaration="yes" method="text" encoding="UTF-8" media-type="text/x-json"/>
<xsl:strip-space elements="*"/>
- <!--contant-->
+ <!--default to no output-->
+ <xsl:variable name="output">false</xsl:variable>
+
+ <!--constant-->
<xsl:variable name="d">0123456789</xsl:variable>
<!-- ignore document text -->
@@ -130,45 +133,83 @@
<xsl:template match="text()[translate(.,'TRUE','true')='true']">true</xsl:template>
<xsl:template match="text()[translate(.,'FALSE','false')='false']">false</xsl:template>
- <!-- object -->
+ <!-- objects and arrays -->
<xsl:template match="*" name="base">
- <xsl:if test="not(preceding-sibling::*)">{</xsl:if>
- <xsl:call-template name="escape-string">
- <xsl:with-param name="s" select="name()"/>
- </xsl:call-template>
- <xsl:text>:</xsl:text>
- <!-- check type of node -->
<xsl:choose>
- <!-- null nodes -->
- <xsl:when test="count(child::node())=0">null</xsl:when>
- <!-- other nodes -->
- <xsl:otherwise>
- <xsl:apply-templates select="child::node()"/>
- </xsl:otherwise>
- </xsl:choose>
- <!-- end of type check -->
- <xsl:if test="following-sibling::*">,</xsl:if>
- <xsl:if test="not(following-sibling::*)">}</xsl:if>
- </xsl:template>
+ <!-- complete array -->
+ <xsl:when test="(count(../*[name(current())=name()])=count(../*)) and count(../*[name(current())=name()])>1">
+ <xsl:variable name="el" select="name()"/>
+ <xsl:if test="not(following-sibling::*[name()=$el])">
+ <xsl:text>[</xsl:text>
+ <xsl:for-each select="../*[name()=$el]">
+ <xsl:if test="position()!=1">,</xsl:if>
+ <xsl:choose>
+ <xsl:when test="not(child::node())">
+ <xsl:text>null</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates select="child::node()"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ <xsl:text>]</xsl:text>
+ </xsl:if>
+ </xsl:when>
- <!-- array -->
- <xsl:template match="*[count(../*[name(../*)=name(.)])=count(../*) and count(../*)>1]">
- <xsl:if test="not(preceding-sibling::*)">[</xsl:if>
- <xsl:choose>
- <xsl:when test="not(child::node())">
- <xsl:text>null</xsl:text>
+ <!-- partial array -->
+ <xsl:when test="count(../*[name(current())=name()])>1">
+ <xsl:if test="not(preceding-sibling::*)">{</xsl:if>
+ <xsl:variable name="el" select="name()"/>
+ <xsl:if test="not(following-sibling::*[name()=$el])">
+ <xsl:call-template name="escape-string">
+ <xsl:with-param name="s" select="$el"/>
+ </xsl:call-template>
+ <xsl:text>:[</xsl:text>
+ <xsl:for-each select="../*[name()=$el]">
+ <xsl:if test="position()!=1">,</xsl:if>
+ <xsl:choose>
+ <xsl:when test="not(child::node())">
+ <xsl:text>null</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates select="child::node()"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ <xsl:text>]</xsl:text>
+ <xsl:if test="following-sibling::*">,</xsl:if>
+ </xsl:if>
+ <xsl:if test="not(following-sibling::*)">}</xsl:if>
</xsl:when>
+
+ <!-- object -->
<xsl:otherwise>
- <xsl:apply-templates select="child::node()"/>
+ <xsl:if test="not(preceding-sibling::*)">{</xsl:if>
+ <xsl:call-template name="escape-string">
+ <xsl:with-param name="s" select="name()"/>
+ </xsl:call-template>
+ <xsl:text>:</xsl:text>
+ <!-- check type of node -->
+ <xsl:choose>
+ <!-- null nodes -->
+ <xsl:when test="count(child::node())=0">null</xsl:when>
+ <!-- other nodes -->
+ <xsl:otherwise>
+ <xsl:apply-templates select="child::node()"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ <!-- end of type check -->
+ <xsl:if test="following-sibling::*">,</xsl:if>
+ <xsl:if test="not(following-sibling::*)">}</xsl:if>
</xsl:otherwise>
</xsl:choose>
- <xsl:if test="following-sibling::*">,</xsl:if>
- <xsl:if test="not(following-sibling::*)">]</xsl:if>
</xsl:template>
-
+
<!-- convert root element to an anonymous container -->
<xsl:template match="/">
- <xsl:apply-templates select="node()"/>
+ <xsl:if test="$output='true'">
+ <xsl:apply-templates select="node()"/>
+ </xsl:if>
</xsl:template>
</xsl:stylesheet>
More information about the commits
mailing list