Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cpp/ql/lib/change-notes/2022-08-22-xml-rename.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
category: deprecated
---
* Classes/predicates that had upper-case acronym XML in their name have been renamed to Xml to follow our style-guide.
The old name still exists as a deprecated alias.
95 changes: 61 additions & 34 deletions cpp/ql/lib/semmle/code/cpp/XML.qll
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ private class TXmlLocatable =
@xmldtd or @xmlelement or @xmlattribute or @xmlnamespace or @xmlcomment or @xmlcharacters;

/** An XML element that has a location. */
class XMLLocatable extends @xmllocatable, TXmlLocatable {
class XmlLocatable extends @xmllocatable, TXmlLocatable {
/** Gets the source location for this element. */
Location getLocation() { xmllocations(this, result) }

Expand All @@ -32,13 +32,16 @@ class XMLLocatable extends @xmllocatable, TXmlLocatable {
string toString() { none() } // overridden in subclasses
}

/** DEPRECATED: Alias for XmlLocatable */
deprecated class XMLLocatable = XmlLocatable;

/**
* An `XMLParent` is either an `XMLElement` or an `XMLFile`,
* An `XmlParent` is either an `XmlElement` or an `XmlFile`,
* both of which can contain other elements.
*/
class XMLParent extends @xmlparent {
XMLParent() {
// explicitly restrict `this` to be either an `XMLElement` or an `XMLFile`;
class XmlParent extends @xmlparent {
XmlParent() {
// explicitly restrict `this` to be either an `XmlElement` or an `XmlFile`;
// the type `@xmlparent` currently also includes non-XML files
this instanceof @xmlelement or xmlEncoding(this, _)
}
Expand All @@ -50,28 +53,28 @@ class XMLParent extends @xmlparent {
string getName() { none() } // overridden in subclasses

/** Gets the file to which this XML parent belongs. */
XMLFile getFile() { result = this or xmlElements(this, _, _, _, result) }
XmlFile getFile() { result = this or xmlElements(this, _, _, _, result) }

/** Gets the child element at a specified index of this XML parent. */
XMLElement getChild(int index) { xmlElements(result, _, this, index, _) }
XmlElement getChild(int index) { xmlElements(result, _, this, index, _) }

/** Gets a child element of this XML parent. */
XMLElement getAChild() { xmlElements(result, _, this, _, _) }
XmlElement getAChild() { xmlElements(result, _, this, _, _) }

/** Gets a child element of this XML parent with the given `name`. */
XMLElement getAChild(string name) { xmlElements(result, _, this, _, _) and result.hasName(name) }
XmlElement getAChild(string name) { xmlElements(result, _, this, _, _) and result.hasName(name) }

/** Gets a comment that is a child of this XML parent. */
XMLComment getAComment() { xmlComments(result, _, this, _) }
XmlComment getAComment() { xmlComments(result, _, this, _) }

/** Gets a character sequence that is a child of this XML parent. */
XMLCharacters getACharactersSet() { xmlChars(result, _, this, _, _, _) }
XmlCharacters getACharactersSet() { xmlChars(result, _, this, _, _, _) }

/** Gets the depth in the tree. (Overridden in XMLElement.) */
/** Gets the depth in the tree. (Overridden in XmlElement.) */
int getDepth() { result = 0 }

/** Gets the number of child XML elements of this XML parent. */
int getNumberOfChildren() { result = count(XMLElement e | xmlElements(e, _, this, _, _)) }
int getNumberOfChildren() { result = count(XmlElement e | xmlElements(e, _, this, _, _)) }

/** Gets the number of places in the body of this XML parent where text occurs. */
int getNumberOfCharacterSets() { result = count(int pos | xmlChars(_, _, this, pos, _, _)) }
Expand All @@ -92,9 +95,12 @@ class XMLParent extends @xmlparent {
string toString() { result = this.getName() }
}

/** DEPRECATED: Alias for XmlParent */
deprecated class XMLParent = XmlParent;

/** An XML file. */
class XMLFile extends XMLParent, File {
XMLFile() { xmlEncoding(this, _) }
class XmlFile extends XmlParent, File {
XmlFile() { xmlEncoding(this, _) }

/** Gets a printable representation of this XML file. */
override string toString() { result = this.getName() }
Expand All @@ -120,15 +126,18 @@ class XMLFile extends XMLParent, File {
string getEncoding() { xmlEncoding(this, result) }

/** Gets the XML file itself. */
override XMLFile getFile() { result = this }
override XmlFile getFile() { result = this }

/** Gets a top-most element in an XML file. */
XMLElement getARootElement() { result = this.getAChild() }
XmlElement getARootElement() { result = this.getAChild() }

/** Gets a DTD associated with this XML file. */
XMLDTD getADTD() { xmlDTDs(result, _, _, _, this) }
XmlDTD getADTD() { xmlDTDs(result, _, _, _, this) }

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase.

Acronyms in getADTD should be PascalCase/camelCase
}

/** DEPRECATED: Alias for XmlFile */
deprecated class XMLFile = XmlFile;

/**
* An XML document type definition (DTD).
*
Expand All @@ -140,7 +149,7 @@ class XMLFile extends XMLParent, File {
* <!ELEMENT lastName (#PCDATA)>
* ```
*/
class XMLDTD extends XMLLocatable, @xmldtd {
class XmlDTD extends XmlLocatable, @xmldtd {

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase.

Acronyms in XmlDTD should be PascalCase/camelCase
/** Gets the name of the root element of this DTD. */
string getRoot() { xmlDTDs(this, result, _, _, _) }

Expand All @@ -154,7 +163,7 @@ class XMLDTD extends XMLLocatable, @xmldtd {
predicate isPublic() { not xmlDTDs(this, _, "", _, _) }

/** Gets the parent of this DTD. */
XMLParent getParent() { xmlDTDs(this, _, _, _, result) }
XmlParent getParent() { xmlDTDs(this, _, _, _, result) }

override string toString() {
this.isPublic() and
Expand All @@ -165,6 +174,9 @@ class XMLDTD extends XMLLocatable, @xmldtd {
}
}

/** DEPRECATED: Alias for XmlDTD */
deprecated class XMLDTD = XmlDTD;

/**
* An XML element in an XML file.
*
Expand All @@ -176,18 +188,18 @@ class XMLDTD extends XMLLocatable, @xmldtd {
* </manifest>
* ```
*/
class XMLElement extends @xmlelement, XMLParent, XMLLocatable {
class XmlElement extends @xmlelement, XmlParent, XmlLocatable {
/** Holds if this XML element has the given `name`. */
predicate hasName(string name) { name = this.getName() }

/** Gets the name of this XML element. */
override string getName() { xmlElements(this, result, _, _, _) }

/** Gets the XML file in which this XML element occurs. */
override XMLFile getFile() { xmlElements(this, _, _, _, result) }
override XmlFile getFile() { xmlElements(this, _, _, _, result) }

/** Gets the parent of this XML element. */
XMLParent getParent() { xmlElements(this, _, result, _, _) }
XmlParent getParent() { xmlElements(this, _, result, _, _) }

/** Gets the index of this XML element among its parent's children. */
int getIndex() { xmlElements(this, _, _, result, _) }
Expand All @@ -196,7 +208,7 @@ class XMLElement extends @xmlelement, XMLParent, XMLLocatable {
predicate hasNamespace() { xmlHasNs(this, _, _) }

/** Gets the namespace of this XML element, if any. */
XMLNamespace getNamespace() { xmlHasNs(this, result, _) }
XmlNamespace getNamespace() { xmlHasNs(this, result, _) }

/** Gets the index of this XML element among its parent's children. */
int getElementPositionIndex() { xmlElements(this, _, _, result, _) }
Expand All @@ -205,10 +217,10 @@ class XMLElement extends @xmlelement, XMLParent, XMLLocatable {
override int getDepth() { result = this.getParent().getDepth() + 1 }

/** Gets an XML attribute of this XML element. */
XMLAttribute getAnAttribute() { result.getElement() = this }
XmlAttribute getAnAttribute() { result.getElement() = this }

/** Gets the attribute with the specified `name`, if any. */
XMLAttribute getAttribute(string name) { result.getElement() = this and result.getName() = name }
XmlAttribute getAttribute(string name) { result.getElement() = this and result.getName() = name }

/** Holds if this XML element has an attribute with the specified `name`. */
predicate hasAttribute(string name) { exists(this.getAttribute(name)) }
Expand All @@ -220,6 +232,9 @@ class XMLElement extends @xmlelement, XMLParent, XMLLocatable {
override string toString() { result = this.getName() }
}

/** DEPRECATED: Alias for XmlElement */
deprecated class XMLElement = XmlElement;

/**
* An attribute that occurs inside an XML element.
*
Expand All @@ -230,18 +245,18 @@ class XMLElement extends @xmlelement, XMLParent, XMLLocatable {
* android:versionCode="1"
* ```
*/
class XMLAttribute extends @xmlattribute, XMLLocatable {
class XmlAttribute extends @xmlattribute, XmlLocatable {
/** Gets the name of this attribute. */
string getName() { xmlAttrs(this, _, result, _, _, _) }

/** Gets the XML element to which this attribute belongs. */
XMLElement getElement() { xmlAttrs(this, result, _, _, _, _) }
XmlElement getElement() { xmlAttrs(this, result, _, _, _, _) }

/** Holds if this attribute has a namespace. */
predicate hasNamespace() { xmlHasNs(this, _, _) }

/** Gets the namespace of this attribute, if any. */
XMLNamespace getNamespace() { xmlHasNs(this, result, _) }
XmlNamespace getNamespace() { xmlHasNs(this, result, _) }

/** Gets the value of this attribute. */
string getValue() { xmlAttrs(this, _, _, result, _, _) }
Expand All @@ -250,6 +265,9 @@ class XMLAttribute extends @xmlattribute, XMLLocatable {
override string toString() { result = this.getName() + "=" + this.getValue() }
}

/** DEPRECATED: Alias for XmlAttribute */
deprecated class XMLAttribute = XmlAttribute;

/**
* A namespace used in an XML file.
*
Expand All @@ -259,7 +277,7 @@ class XMLAttribute extends @xmlattribute, XMLLocatable {
* xmlns:android="http://schemas.android.com/apk/res/android"
* ```
*/
class XMLNamespace extends XMLLocatable, @xmlnamespace {
class XmlNamespace extends XmlLocatable, @xmlnamespace {
/** Gets the prefix of this namespace. */
string getPrefix() { xmlNs(this, result, _, _) }

Expand All @@ -276,6 +294,9 @@ class XMLNamespace extends XMLLocatable, @xmlnamespace {
}
}

/** DEPRECATED: Alias for XmlNamespace */
deprecated class XMLNamespace = XmlNamespace;

/**
* A comment in an XML file.
*
Expand All @@ -285,17 +306,20 @@ class XMLNamespace extends XMLLocatable, @xmlnamespace {
* <!-- This is a comment. -->
* ```
*/
class XMLComment extends @xmlcomment, XMLLocatable {
class XmlComment extends @xmlcomment, XmlLocatable {
/** Gets the text content of this XML comment. */
string getText() { xmlComments(this, result, _, _) }

/** Gets the parent of this XML comment. */
XMLParent getParent() { xmlComments(this, _, result, _) }
XmlParent getParent() { xmlComments(this, _, result, _) }

/** Gets a printable representation of this XML comment. */
override string toString() { result = this.getText() }
}

/** DEPRECATED: Alias for XmlComment */
deprecated class XMLComment = XmlComment;

/**
* A sequence of characters that occurs between opening and
* closing tags of an XML element, excluding other elements.
Expand All @@ -306,16 +330,19 @@ class XMLComment extends @xmlcomment, XMLLocatable {
* <content>This is a sequence of characters.</content>
* ```
*/
class XMLCharacters extends @xmlcharacters, XMLLocatable {
class XmlCharacters extends @xmlcharacters, XmlLocatable {
/** Gets the content of this character sequence. */
string getCharacters() { xmlChars(this, result, _, _, _, _) }

/** Gets the parent of this character sequence. */
XMLParent getParent() { xmlChars(this, _, result, _, _, _) }
XmlParent getParent() { xmlChars(this, _, result, _, _, _) }

/** Holds if this character sequence is CDATA. */
predicate isCDATA() { xmlChars(this, _, _, _, 1, _) }

/** Gets a printable representation of this XML character sequence. */
override string toString() { result = this.getCharacters() }
}

/** DEPRECATED: Alias for XmlCharacters */
deprecated class XMLCharacters = XmlCharacters;
2 changes: 1 addition & 1 deletion cpp/ql/test/library-tests/files/Files.ql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ string describe(File f) {
f.compiledAsCpp() and
result = "C++"
or
f instanceof XMLParent and
f instanceof XmlParent and
result = "XMLParent" // regression tests a bug in the characteristic predicate of XMLParent
}

Expand Down
5 changes: 5 additions & 0 deletions csharp/ql/lib/change-notes/2022-08-22-xml-rename.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
category: deprecated
---
* Classes/predicates that had upper-case acronym XML in their name have been renamed to Xml to follow our style-guide.
The old name still exists as a deprecated alias.
18 changes: 9 additions & 9 deletions csharp/ql/lib/semmle/code/asp/WebConfig.qll
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import csharp
/**
* A `Web.config` file.
*/
class WebConfigXml extends XMLFile {
class WebConfigXml extends XmlFile {
WebConfigXml() { this.getName().matches("%Web.config") }
}

/** DEPRECATED: Alias for WebConfigXml */
deprecated class WebConfigXML = WebConfigXml;

/** A `<configuration>` tag in an ASP.NET configuration file. */
class ConfigurationXmlElement extends XMLElement {
class ConfigurationXmlElement extends XmlElement {
ConfigurationXmlElement() { this.getName().toLowerCase() = "configuration" }
}

/** DEPRECATED: Alias for ConfigurationXmlElement */
deprecated class ConfigurationXMLElement = ConfigurationXmlElement;

/** A `<location>` tag in an ASP.NET configuration file. */
class LocationXmlElement extends XMLElement {
class LocationXmlElement extends XmlElement {
LocationXmlElement() {
this.getParent() instanceof ConfigurationXmlElement and
this.getName().toLowerCase() = "location"
Expand All @@ -34,7 +34,7 @@ class LocationXmlElement extends XMLElement {
deprecated class LocationXMLElement = LocationXmlElement;

/** A `<system.web>` tag in an ASP.NET configuration file. */
class SystemWebXmlElement extends XMLElement {
class SystemWebXmlElement extends XmlElement {
SystemWebXmlElement() {
(
this.getParent() instanceof ConfigurationXmlElement
Expand All @@ -49,7 +49,7 @@ class SystemWebXmlElement extends XMLElement {
deprecated class SystemWebXMLElement = SystemWebXmlElement;

/** A `<system.webServer>` tag in an ASP.NET configuration file. */
class SystemWebServerXmlElement extends XMLElement {
class SystemWebServerXmlElement extends XmlElement {
SystemWebServerXmlElement() {
(
this.getParent() instanceof ConfigurationXmlElement
Expand All @@ -64,7 +64,7 @@ class SystemWebServerXmlElement extends XMLElement {
deprecated class SystemWebServerXMLElement = SystemWebServerXmlElement;

/** A `<customErrors>` tag in an ASP.NET configuration file. */
class CustomErrorsXmlElement extends XMLElement {
class CustomErrorsXmlElement extends XmlElement {
CustomErrorsXmlElement() {
this.getParent() instanceof SystemWebXmlElement and
this.getName().toLowerCase() = "customerrors"
Expand All @@ -75,7 +75,7 @@ class CustomErrorsXmlElement extends XMLElement {
deprecated class CustomErrorsXMLElement = CustomErrorsXmlElement;

/** A `<httpRuntime>` tag in an ASP.NET configuration file. */
class HttpRuntimeXmlElement extends XMLElement {
class HttpRuntimeXmlElement extends XmlElement {
HttpRuntimeXmlElement() {
this.getParent() instanceof SystemWebXmlElement and
this.getName().toLowerCase() = "httpruntime"
Expand All @@ -86,7 +86,7 @@ class HttpRuntimeXmlElement extends XMLElement {
deprecated class HttpRuntimeXMLElement = HttpRuntimeXmlElement;

/** A `<forms>` tag under `<system.web><authentication>` in an ASP.NET configuration file. */
class FormsElement extends XMLElement {
class FormsElement extends XmlElement {
FormsElement() {
this = any(SystemWebXmlElement sw).getAChild("authentication").getAChild("forms")
}
Expand All @@ -105,7 +105,7 @@ class FormsElement extends XMLElement {
}

/** A `<httpCookies>` tag in an ASP.NET configuration file. */
class HttpCookiesElement extends XMLElement {
class HttpCookiesElement extends XmlElement {
HttpCookiesElement() { this = any(SystemWebXmlElement sw).getAChild("httpCookies") }

/**
Expand Down
Loading