forked from dom4j/dom4j
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dom4j#48 Validate QName inputs - throw IllegalArgumentException when …
…qualified name contains disallowed character.
- Loading branch information
1 parent
3772e6c
commit bf0e58e
Showing
4 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.dom4j; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* @author Filip Jirsák | ||
*/ | ||
public class AllowedCharsTest { | ||
@Test | ||
public void localName() { | ||
QName.get("element"); | ||
QName.get(":element"); | ||
QName.get("elem:ent"); | ||
} | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class) | ||
public void localNameFail() { | ||
QName.get("!element"); | ||
} | ||
|
||
@Test | ||
public void qname() { | ||
QName.get("element", "http://example.com/namespace"); | ||
QName.get("ns:element", "http://example.com/namespace"); | ||
} | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class) | ||
public void qnameFail1() { | ||
QName.get("ns:elem:ent", "http://example.com/namespace"); | ||
} | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class) | ||
public void qnameFail2() { | ||
QName.get(":nselement", "http://example.com/namespace"); | ||
} | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class) | ||
public void createElementLT() { | ||
DocumentHelper.createElement("element<name"); | ||
} | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class) | ||
public void createElementGT() { | ||
DocumentHelper.createElement("element>name"); | ||
} | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class) | ||
public void createElementAmpersand() { | ||
DocumentHelper.createElement("element&name"); | ||
} | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class) | ||
public void addElement() { | ||
Element root = DocumentHelper.createElement("root"); | ||
root.addElement("element>name"); | ||
} | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class) | ||
public void addElementQualified() { | ||
Element root = DocumentHelper.createElement("root"); | ||
root.addElement("element>name", "http://example.com/namespace"); | ||
} | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class) | ||
public void addElementQualifiedPrefix() { | ||
Element root = DocumentHelper.createElement("root"); | ||
root.addElement("ns:element>name", "http://example.com/namespace"); | ||
} | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class) | ||
public void addElementPrefix() { | ||
Element root = DocumentHelper.createElement("root"); | ||
root.addElement("ns>:element", "http://example.com/namespace"); | ||
} | ||
|
||
//TODO It is illegal to create element or attribute with namespace prefix and empty namespace IRI. | ||
//See https://www.w3.org/TR/2006/REC-xml-names11-20060816/#scoping | ||
} |