Skip to content

Commit

Permalink
handle attribute with text equal to single quote (i.e. ") (#1726)
Browse files Browse the repository at this point in the history
Attribute method is not able to handle the string with a single quote. We trim the quotes from the string without checking its length, and it's causing an issue if string has only one character.
e.g.
val="
  • Loading branch information
hmittal1 authored Jan 29, 2025
1 parent 1f65a45 commit a5f12dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,9 @@ public String getAttribute(String name) {
// remove quote
char c = value.charAt(0);
if (c == '"' || c == '\'') {
if (value.charAt(value.length() - 1) == c) {
if (value.length() == 1) {
return value;
} else if (value.charAt(value.length() - 1) == c) {
return value.substring(1, value.length() - 1);
}
return value.substring(1, value.length());
Expand Down Expand Up @@ -943,4 +945,4 @@ public Object setUserData(String arg0, Object arg1, UserDataHandler arg2) {
return null;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,10 @@ public void noDefaultNamespaceURI() {
assertEquals("http://camel.apache.org/schema/spring", camel.getNamespaceURI());

}

@Test
void findElementWithSingleQuoteValue() {
DOMDocument document = DOMParser.getInstance().parse("<ele attr='\"'/>", "test", null);
assertEquals("\"", document.getChild(0).getAttribute("attr"));
}
}

0 comments on commit a5f12dd

Please sign in to comment.