Skip to content

Commit 175f089

Browse files
committed
Self-referencing object detection
1 parent 54887cb commit 175f089

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

  • src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/client/block

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/client/block/object.xsl

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,34 @@ exclude-result-prefixes="#all"
9595
<xsl:function name="ldh:object-self-thunk" as="item()*" ixsl:updating="yes">
9696
<xsl:param name="context" as="map(*)"/>
9797
<xsl:message>ldh:object-self-thunk</xsl:message>
98-
<xsl:sequence select="
99-
ixsl:resolve($context) =>
100-
ixsl:then(ldh:object-value-thunk#1) =>
101-
ixsl:then(ldh:object-metadata-thunk#1)
102-
"/>
98+
99+
<!-- Check for self-reference and handle it early -->
100+
<xsl:variable name="resource-uri" select="$context('resource-uri')" as="xs:anyURI"/>
101+
<xsl:variable name="block" select="$context('block')" as="element()"/>
102+
<xsl:variable name="about" select="$block/@about" as="xs:anyURI"/>
103+
104+
<xsl:choose>
105+
<xsl:when test="$resource-uri = $about">
106+
<!-- Self-reference detected - render error and return resolved context -->
107+
<xsl:variable name="container" select="$context('container')" as="element()"/>
108+
<xsl:for-each select="$container">
109+
<xsl:result-document href="?." method="ixsl:replace-content">
110+
<div class="alert alert-block">
111+
<strong>Self-referencing object detected: <a href="{$resource-uri}"><xsl:value-of select="$resource-uri"/></a></strong>
112+
</div>
113+
</xsl:result-document>
114+
</xsl:for-each>
115+
<xsl:sequence select="ixsl:resolve($context)"/>
116+
</xsl:when>
117+
<xsl:otherwise>
118+
<!-- Normal processing -->
119+
<xsl:sequence select="
120+
ixsl:resolve($context) =>
121+
ixsl:then(ldh:object-value-thunk#1) =>
122+
ixsl:then(ldh:object-metadata-thunk#1)
123+
"/>
124+
</xsl:otherwise>
125+
</xsl:choose>
103126
</xsl:function>
104127

105128
<!-- only the first HTTP → query‐response lives here -->

0 commit comments

Comments
 (0)