r86423 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86422‎ | r86423 | r86424 >
Date:19:28, 19 April 2011
Author:mkroetzsch
Status:deferred
Tags:
Comment:
check whether QName is allowed before using it in Turtle
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exp_Element.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/export/SMW_Serializer_Turtle.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exp_Element.php
@@ -169,6 +169,18 @@
170170 return $this->m_localname;
171171 }
172172
 173+ /**
 174+ * Check if the local name is qualifies as a local name in XML and
 175+ * Turtle. The function returns true if this is surely the case, and
 176+ * false if it may not be the case. However, we do not check the whole
 177+ * range of allowed Unicode entities for performance reasons.
 178+ *
 179+ * @return boolean
 180+ */
 181+ public function hasAllowedLocalName() {
 182+ return preg_match( '/^[A-Za-z_][-A-Za-z_0-9]*$/u', $this->m_localname );
 183+ }
 184+
173185 }
174186
175187 /**
Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Serializer_Turtle.php
@@ -226,7 +226,7 @@
227227 if ( $element->isBlankNode() ) {
228228 $this->post_ns_buffer .= '[]';
229229 } else {
230 - if ( $element instanceof SMWExpNsResource ) {
 230+ if ( ( $element instanceof SMWExpNsResource ) && ( $element->hasAllowedLocalName() ) ) {
231231 $this->post_ns_buffer .= $element->getQName();
232232 } else {
233233 $this->post_ns_buffer .= '<' . str_replace( '>', '\>', SMWExporter::expandURI( $element->getUri() ) ) . '>';

Status & tagging log